ソースを参照

1.相册权限关闭 扫码页黑屏被拒问题修复

huangxiaodong 1 週間 前
コミット
00050be7f1

+ 42 - 5
创维盒子/code/Class/Guide/QRCodeScanViewController.m

@@ -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];

+ 42 - 5
创维盒子/code/Class/Set/ChangeDevice/QRCodeScanForChangeDeviceViewController.m

@@ -60,15 +60,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];

+ 41 - 5
创维盒子/code/mine/scanToPCLoginViewController.m

@@ -42,15 +42,51 @@
     }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];