如何在 iOS8 中以编程方式知道该应用程序是否可以访问相机 [英] How to know that application have camera access or not programmatically in iOS8
问题描述
我的应用程序使用相机.在 iOS8 中,它们包含一个新的隐私设置 Camera
,用户可以在其中管理为每个应用程序使用相机权限.
My application uses the camera.
In iOS8 they include a new privacy setting, Camera
, where the user can manage
use of camera rights for each application.
问题:
如果用户不允许我的应用程序使用相机,那么我怎么知道我的应用程序无法访问相机.
就像我可以使用 ALAssetsLibrary authorizationStatus
来发现照片库的状态或 ABAddressBookGetAuthorizationStatus
以了解 电话簿 访问的状态.
Problem:
If the user didn't allow my application to use camera then how can i know that
My application have no access for camera.
like i can use ALAssetsLibrary authorizationStatus
to discover the status of the photolibrary
or ABAddressBookGetAuthorizationStatus
to know status of phonebook access.
问题:
我如何知道我的应用程序在 iOS8 中是否可以访问相机,以便我可以提示用户允许我的应用程序访问相机?
Question:
How i can know whether my application has camera access or not in iOS8,
so that I may prompt the user to allow camera access for my application?
我有下面的照相亭打印屏幕有同样的问题就像我的应用程序一样.
I have below print screen of Photo booth which having same problem as my application have.
<小时>当没有摄像头访问时,它只会显示黑屏没有任何消息.
推荐答案
检查AVAuthorizationStatus 用于相机可用性,然后相应地处理案例
Check AVAuthorizationStatus for camera availability and then handle cases accordingly
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");
}
}];
}
这篇关于如何在 iOS8 中以编程方式知道该应用程序是否可以访问相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!