判断是否开启相册、相机权限

相机权限

//需要添加#import 

NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == ALAuthorizationStatusRestricted || authStatus == ALAuthorizationStatusDenied){

     NSLog(@"不允许访问相机");
    //跳转到设置页面中自己的应用下
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    
}

相册权限

//需要添加#import 

ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusRestricted || author ==ALAuthorizationStatusDenied)
{
     NSLog(@"不允许访问相册");
    //跳转到设置页面中自己的应用下
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}

注意

在更改了权限之后,app会自动关闭, 然后试了一下其他的app同样会出现这样的问题,这个崩溃是系统造成的,不知道是它的bug还是它确实需要强行杀掉你的app

你可能感兴趣的:(判断是否开启相册、相机权限)