iOS 8之後相機授權判斷

weixin_34378969發表於2016-08-19

參考http://blog.sina.com.cn/s/blog_b1540f630102w6zn.html

示例程式碼

// 判斷相機授權
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;
}

相關文章