1.判断用户是否有权限访问相册
#import <AssetsLibrary/AssetsLibrary.h>
ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];
if (author == ALAuthorizationStatusRestricted || author ==ALAuthorizationStatusDenied){
//无权限 做一个友好的提示
UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请您设置允许APP访问您的相册\n设置>隐私>照片" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alart show];
return ;
} else {
//打开相册
}
ALAuthorizationStatus是一个系统的枚举。含义如下。
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
AVAuthorizationStatusNotDetermined = 0,// 用户尚未做出选择这个应用程序的问候
AVAuthorizationStatusRestricted,// 此应用程序没有被授权访问的照片数据。可能是家长控制权限
AVAuthorizationStatusDenied,// 用户已经明确否认了这一照片数据的应用程序访问
AVAuthorizationStatusAuthorized// 用户已经授权应用访问照片数据
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
2、判断用户是否有权限访问相机
iOS7之前都可以访问相机,iOS7之后访问相机有权限设置
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
{
//无权限 做一个友好的提示
UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请您设置允许APP访问您的相机\n设置>隐私>相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alart show];
return ;
} else {
//调用相机
}
3、判断定位服务是否可用
if ([CLLocationManager locationServicesEnabled] &&
([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized
|| [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {
//定位功能可用,开始定位
_locationManger = [[CLLocationManager alloc] init];
locationManger.delegate = self;
[locationManger startUpdatingLocation];
}
else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){
NSlog("定位功能不可用,提示用户或忽略");
}
网友评论