|
@@ -53,15 +53,52 @@
|
|
|
}else{
|
|
|
NSLog(@"未开启相机权限,请前往设置中开启");
|
|
|
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
|
|
- if (granted){
|
|
|
- mainBlock(^{
|
|
|
- [self startScan];
|
|
|
- });
|
|
|
- }
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if (granted) {
|
|
|
+ // 用户同意授权
|
|
|
+ [self startScan];;
|
|
|
+ } else {
|
|
|
+ // 用户拒绝授权
|
|
|
+ [self showPermissionDeniedAlert];
|
|
|
+ }
|
|
|
+ });
|
|
|
}];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)showPermissionDeniedAlert {
|
|
|
+
|
|
|
+ NSString * titleStr = NSLocalizedString(@"Camera_permissions_disabled",nil);
|
|
|
+ NSString * tipStr = NSLocalizedString(@"Camera_permissions_open_tip",nil);
|
|
|
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleStr
|
|
|
+ message:tipStr
|
|
|
+ preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+
|
|
|
+ NSString* cancelStr = NSLocalizedString(@"other_cancel",nil);
|
|
|
+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelStr style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ [self backBtnPressed];
|
|
|
+ }];
|
|
|
+
|
|
|
+ NSString*settingStr = NSLocalizedString(@"set_Privacy_button_title",nil);
|
|
|
+ UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:settingStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self backBtnPressed];
|
|
|
+
|
|
|
+ // 跳转到应用设置页面
|
|
|
+ NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
|
+ if ([[UIApplication sharedApplication] canOpenURL:settingsURL]) {
|
|
|
+ [[UIApplication sharedApplication] openURL:settingsURL options:@{} completionHandler:nil];
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [alert addAction:cancelAction];
|
|
|
+ [alert addAction:settingsAction];
|
|
|
+
|
|
|
+ [self presentViewController:alert animated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
-(void)viewWillDisappear:(BOOL)animated
|
|
|
{
|
|
|
[super viewWillDisappear:animated];
|