iOS 常用授权判断

来源:互联网 发布:冯大辉 离职 知乎 编辑:程序博客网 时间:2024/05/17 08:11
1.相机授权判断:
//判断相机是否已授权      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {          AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];          if (authStatus == ALAuthorizationStatusDenied||authStatus == ALAuthorizationStatusRestricted) {              [self setAlertControllerWithTitle:@"提示" message:@"请前往设置->隐私->相机授权应用拍照权限" actionTitle:@"确定"];              return ;          }      } //判断相册是否已授权      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {          ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];          if (authStatus == ALAuthorizationStatusDenied) {              [self setAlertControllerWithTitle:@"提示" message:@"请前往设置->隐私->相册授权应用访问相册权限" actionTitle:@"确定"];              return;          }        } 


2.定位授权判断:
这里就要查看CLLocationManager的授权状态,此方法会返回当前授权状态:[CLLocationManager authorizationStatus]授权状态为枚举值:kCLAuthorizationStatusNotDetermined     //用户尚未对该应用程序作出选择kCLAuthorizationStatusRestricted        //应用程序的定位权限被限制 kCLAuthorizationStatusAuthorizedAlways  //一直允许获取定位kCLAuthorizationStatusAuthorizedWhenInUse  //在使用时允许获取定位kCLAuthorizationStatusAuthorized        //已废弃,相当于一直允许获取定位kCLAuthorizationStatusDenied            //拒绝获取定位if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {        //定位功能可用}else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {//定位不能用}

原创粉丝点击