1.判断用户是否有权限访问相册ide
#import <AVFoundation/AVFoundation.h>图片
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];get
if(authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){it
[SVProgressHUD showErrorWithStatus:@"没有访问权限"];io
}else{import
msg = @"保存图片失败" ;权限
[SVProgressHUD showErrorWithStatus:msg];程序
}方法
// AVAuthorizationStatus是个枚举,有4个值,分别以下:im
// AVAuthorizationStatusNotDetermined =0,//用户没有作出选择
// AVAuthorizationStatusRestricted,//这个应用程序没有被受权访问照片数据。
// AVAuthorizationStatusDenied,//用户已经明确否定了这一应用程序访问数据的照片。
// AVAuthorizationStatusAuthorized//用户已受权该应用程序访问数据的照片。
#import ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus]; if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied) { //无权限 } typedef enum { kCLAuthorizationStatusNotDetermined = 0, // 用户还没有作出选择这个应用程序的问候 kCLAuthorizationStatusRestricted, // 此应用程序没有被受权访问的照片数据。多是家长控制权限 kCLAuthorizationStatusDenied, // 用户已经明确否定了这一照片数据的应用程序访问 kCLAuthorizationStatusAuthorized // 用户已经受权应用访问照片数据 } CLAuthorizationStatus;
2.判断用户是否有权限访问相机
iOS7以前均可以访问相机,iOS7以后访问相机有权限设置
#import #import AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) { //无权限 }
3.判断是否开启定位服务
[CLLocationManagerlocationServicesEnabled] //检测的是整个的iOS系统的定位服务是否开启 检测当前应用的定位服务是否开启须要经过一下方法来检测 - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error