判断应用是否有访问相册和相机的权限

1:导入avfoundtion框架

   pch中导入头文件

#import

#import

#import


2:判断的代码


 if (sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {

            //判断相册权限

            ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];

            if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){

                //无权限

                if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)) {

                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"照片权限被禁用" message:@"请在iPhone'设置-隐私-照片'中允许抖抖访问你的照片" preferredStyle:UIAlertControllerStyleAlert];

                    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];

                    [alertController addAction:cancelAction];

                    [self presentViewController:alertController animated:YES completion:nil];

                    return;

                

                }else{

                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"照片权限被禁用" message:@"请在iPhone'设置-隐私-照片'中允许抖抖访问你的照片" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

                    [alertView show];

                    return;

                }

            }else{

       //有相册权限

}

            

        }else if (sourceType == UIImagePickerControllerSourceTypeCamera){

            

            AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

            if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){

                

                //无权限

                if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)) {

                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"相机被禁用" message:@"请在iPhone'设置-隐私-相机'中允许抖抖访问你的相机" preferredStyle:UIAlertControllerStyleAlert];

                    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];

                    [alertController addAction:cancelAction];

                    [self presentViewController:alertController animated:YES completion:nil];

                    return;

                

                }else{

                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"相机被禁用" message:@"请在iPhone'设置-隐私-相机'中允许抖抖访问你的相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

                    [alertView show];

                    return;

                }

            }else{

//有相机权限

               

          }

        }


你可能感兴趣的:(ios)