IOS 去设置开启权限


//调用打开相册权限设置
- (void)callCameraPermissions
{
    //相机权限
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus ==AVAuthorizationStatusRestricted ||//此应用程序没有被授权访问的照片数据。
        authStatus ==AVAuthorizationStatusDenied)  //用户已经明确否认了这一照片数据的应用程序访问
    {
        UIAlertController *logoutAlter=[UIAlertController alertControllerWithTitle:WYLocalizedString(@"service_public_open_camera_permissions", @"去'设置'打开相机权限") message:@"" preferredStyle:UIAlertControllerStyleAlert];
        [logoutAlter addAction:[UIAlertAction actionWithTitle:WYLocalizedString(@"co_cancel", @"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            // NSLog(@"点击取消");
        }]];
        [logoutAlter addAction:[UIAlertAction actionWithTitle:WYLocalizedString(@"co_ok", @"ok") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            // 无权限 引导去开启
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
        }]];
        [self presentViewController:logoutAlter animated:YES completion:nil];
    }else{
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            NSLog(@"权限开启时执行的代码");
        }else{
            HRLog(@"手机不支持相机");
        }
    }
}

你可能感兴趣的:(IOS 去设置开启权限)