相机权限
//需要添加#import <AVFoundation/AVFoundation.h>
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == ALAuthorizationStatusRestricted || authStatus == ALAuthorizationStatusDenied){
NSLog(@"不允许访问相机");
//跳转到设置页面中自己的应用下
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
相册权限
//需要添加#import <AssetsLibrary/AssetsLibrary.h>
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusRestricted || author ==ALAuthorizationStatusDenied)
{
NSLog(@"不允许访问相册");
//跳转到设置页面中自己的应用下
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
注意
在更改了权限之后,app会自动关闭, 然后试了一下其他的app同样会出现这样的问题,这个崩溃是系统造成的,不知道是它的bug还是它确实需要强行杀掉你的app