ScanBackupController.mm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2013-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import <MobileCoreServices/UTCoreTypes.h>
  21. #import "ScanBackupController.h"
  22. #import "MBProgressHUD.h"
  23. #import "PortraitNavigationController.h"
  24. #import "UIDefines.h"
  25. #ifdef DEBUG
  26. static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
  27. #else
  28. static const DDLogLevel ddLogLevel = DDLogLevelWarning;
  29. #endif
  30. @implementation ScanBackupController
  31. + (BOOL)canScan {
  32. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  33. NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
  34. return [mediaTypes containsObject:(NSString *)kUTTypeMovie];
  35. }
  36. return NO;
  37. }
  38. - (void)startScan {
  39. [MBProgressHUD hideHUDForView:self.containingViewController.view animated:NO];
  40. [MBProgressHUD showHUDAddedTo:self.containingViewController.view animated:YES];
  41. QRScannerViewController *qrController = [[QRScannerViewController alloc] init];
  42. qrController.delegate = self;
  43. qrController.title = NSLocalizedString(@"scan_backup", nil);
  44. UINavigationController *nav = [[PortraitNavigationController alloc] initWithRootViewController:qrController];
  45. nav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
  46. nav.navigationBar.tintColor = [Colors mainThemeDark];
  47. nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  48. [self.containingViewController presentViewController:nav animated:YES completion:nil];
  49. }
  50. #pragma mark - QRScannerViewControllerDelegate
  51. - (void)qrScannerViewController:(QRScannerViewController *)controller didScanResult:(NSString *)result {
  52. DDLogVerbose(@"Scanned data: %@", result);
  53. [MBProgressHUD hideHUDForView:self.containingViewController.view animated:NO];
  54. [self.delegate didScanBackup:result];
  55. [controller dismissViewControllerAnimated:YES completion:nil];
  56. }
  57. - (void)qrScannerViewControllerDidCancel:(QRScannerViewController *)controller {
  58. DDLogVerbose(@"Scan cancelled");
  59. [MBProgressHUD hideHUDForView:self.containingViewController.view animated:NO];
  60. [controller dismissViewControllerAnimated:YES completion:nil];
  61. }
  62. @end