您的位置:首页 > 其它

判断是否有权限访问相机,相册,定位

2014-05-14 13:56 323 查看
1.判断用户是否有权限访问相册/相机

//判断是否拥有权限

AVAuthorizationStatus authStatus = [AVCaptureDevice
authorizationStatusForMediaType:AVMediaTypeVideo];

NSLog(@"status = %i",authStatus);

switch (authStatus) {

case
AVAuthorizationStatusNotDetermined:

{

[AVCaptureDevice
requestAccessForMediaType:AVMediaTypeVideo
completionHandler:^(BOOL granted) {

if (granted)

{

// NSLog(@"User Granted");

}

else

{

// NSLog(@"User Denied");

}

}];

break;

}

case
AVAuthorizationStatusRestricted:

case
AVAuthorizationStatusDenied:

{

UIAlertView *alterView = [[UIAlertView
alloc] initWithTitle:@"相机授权"
message:@"没有权限访问您的相机,请在“设置-隐私-相机”中允许使用"
delegate:nil
cancelButtonTitle:@"取消"
otherButtonTitles:nil,
nil];

[alterView show];

break;

}

default:

{

//拍照

//从相册获取

break;

}

}

typedef enum {

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

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

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

kCLAuthorizationStatusAuthorized // 用户已经授权应用访问照片数据
} CLAuthorizationStatus;

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

[CLLocationManagerlocationServicesEnabled] //检测的是整个的iOS系统的定位服务是否开启
检测当前应用的定位服务是否开启需要通过一下方法来检测
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: