这篇是本人在回顾以往封装的类的一些分享,包含了通用设置的权限的调起和相机相册相关的权限设置的调起。
1、获取通用设置的权限
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
这个方法比较通用,直接进入设置界面,自己去找到相关权限去进行设置。
2、检查并更改相机的权限
// 检测相机权限
- (BOOL)searchCamreaLimit {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
{
dispatch_async(dispatch_get_main_queue(), ^{ [self setAlertWithTitle:@"检查相机权限" message:@"请前往设置->地盘->相机->打开权限"]; }); return NO; } return YES;
}
这个方法比较有目的性,直接是去设置相机的权限
3、检查并更改应用相册的权限
// 检测相册权限
- (BOOL)searchPhotosLimit
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == kCLAuthorizationStatusRestricted || authStatus == kCLAuthorizationStatusDenied) {
dispatch_async(dispatch_get_main_queue(), ^{
[self setAlertWithTitle:@"检查相册权限" message:@"请前往设置->地盘->相册->打开权限"];
});
return NO;
}
return YES;
}