iOS开发笔记

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

2016-04-07  本文已影响8900人  这人很懒

1、判断用户是否获取了相册的访问权限

#import<AssetsLibrary/AssetsLibrary.h>

ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];

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

//无权限

}

typedefenum{

ALAuthorizationStatusNotDetermined =0  // 用户尚未做出选择这个应用程序的问候

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

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

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

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

//such as parental controls being in place.

ALAuthorizationStatusDenied  // 用户已经明确否认了这一照片数据的应用程序访问

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

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

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

}

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

#import<AVFoundation/AVCaptureDevice.h>

#import<AVFoundation/AVMediaFormat.h>

AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];

if(authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){

//无权限

}

3.判断是否开启定位服务

[CLLocationManagerlocationServicesEnabled]//检测的是整个的iOS系统的定位服务是否开启检测当前应用的定位服务是否开启需要通过一下方法来检测

- (void)locationManager:(CLLocationManager*)managerdidFailWithError:(NSError*)error

上一篇 下一篇

猜你喜欢

热点阅读