我的应用程序使用相机.
在iOS8中,他们包括一个新的隐私设置,相机,用户可以管理的位置
对每个应用程序使用摄像机权限.
在iOS8中,他们包括一个新的隐私设置,相机,用户可以管理的位置
对每个应用程序使用摄像机权限.
问题:
如果用户不允许我的应用程序使用相机,那么我如何才能知道
我的应用程序无法访问相机.
像我可以使用ALAssetsLibrary authorizationStatus来发现照片库的状态
或ABAddressBookGetAuthorizationStatus来了解电话簿访问状态.
题:
在iOS8中我如何知道我的应用程序是否具有相机访问权限,
这样我可以提示用户允许相机访问我的应用程序?
我有下面打印屏幕的照片摊位有同样的问题
作为我的应用程序.
当没有相机访问时,它只会显示黑屏无信息.
解决方法
检查
AVAuthorizationStatus摄像机的可用性,然后处理案件
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(status == AVAuthorizationStatusAuthorized) {
// authorized
} else if(status == AVAuthorizationStatusDenied){
// denied
} else if(status == AVAuthorizationStatusRestricted){
// restricted
} else if(status == AVAuthorizationStatusNotDetermined){
// not determined
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access");
} else {
NSLog(@"Not granted access");
}
}];
}