iOS 8以降カメラ認証判定

1199 ワード

参照http://blog.sina.com.cn/s/blog_b 1540 f 6302 w 6 zn.
サンプルコード
//       
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"      " message:@"    -  -    52   " preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"    " style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"    " style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self cancle];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
    return;
}