iOS开发中判断相册、相机、位置等权限

Posted by
3.判断用户是否授权应用获取定位权限的完整代码:
if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) { //定位功能可用}else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {//定位不能用}

有不足之处还望补充。

// User has authorized this application to access photos data.

在特定场景下我们需要判断用户是否允许应用获取定位权限

//such as parental controls being in place.

2.判断用户手机是否开启了定位服务:
这里就要查看CLLocationManager的授权状态,此方法会返回当前授权状态:[CLLocationManager authorizationStatus]授权状态为枚举值:kCLAuthorizationStatusNotDetermined //用户尚未对该应用程序作出选择kCLAuthorizationStatusRestricted //应用程序的定位权限被限制 kCLAuthorizationStatusAuthorizedAlways //一直允许获取定位kCLAuthorizationStatusAuthorizedWhenInUse //在使用时允许获取定位kCLAuthorizationStatusAuthorized //已废弃,相当于一直允许获取定位kCLAuthorizationStatusDenied //拒绝获取定位

ALAuthorizationStatusRestricted  //
此应用程序没有被授权访问的照片数据。可能是家长控制权限

1.导入类库:
#import <CoreLocation/CLLocationManager.h>

//无权限

// User has not yet made a choice with regards to this application

if(author == ALAuthorizationStatusRestricted || author
==ALAuthorizationStatusDenied){

typedefenum{

// The user cannot change this application’s status, possibly due to
active restrictions

ALAuthorizationStatusAuthorized  //用户已经授权应用访问照片数据

2.判断用户是否有权限访问相机

#import<AssetsLibrary/AssetsLibrary.h>

}

,// This application is not authorized to access photo data.

// User has explicitly denied this application access to photos data.

相关文章

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注