判断是否有权限访问相机,相册,定位
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
//判断是否拥有权限
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
相关文章推荐
- iOS判断是否有权限访问相机,相册,定位
- 判断是否有权限访问相机,相册,定位
- iOS iOS判断是否有权限访问相机,相册,定位
- 判断是否有权限访问相机,相册,定位
- ios判断是否有权限访问相机,相册,定位
- iOS判断是否有权限访问相机,相册,定位
- 判断是否有权限访问相机,相册,定位
- 判断是否有权限访问相机,相册,定位
- ios 判断是否有权限访问相机,相册,定位
- iOS判断是否有权限访问相机,相册,定位
- iOS判断是否有权限访问相机,相册,定位
- 判断是否开启相机相册、定位权限并去系统开启权限
- 判断应用是否有访问相册和相机的权限
- iOS-判断相册,相机,定位权限是否打开
- 判断系统定位是否开启,判断是否开启相机访问 ,判断是否开启相册访问
- iOS 判断是否有权限访问相机,相册
- iOS相机 相册 麦克风 定位等权限是否拥有
- 判断是否有相册、相机 权限
- 查询是否有权限访问相机和相册
- swift-判断是否已获得相机、相册权限