问题描述
当我的应用在 iOS 8 上第一次尝试访问摄像头时,用户会看到一个摄像头权限对话框,很像 iOS 7 中用于麦克风访问的麦克风对话框.
When my app tries to access the camera for the first time on iOS 8, the user is presented with a camera permission dialog, much like the microphone one for microphone access in iOS 7.
在 iOS 7 中,可以预先调用麦克风权限对话框并查看是否授予权限(参见 这个问题,例如).是否有类似的方法可以在 iOS 8 中调用相机权限对话框?该对话框是否可以合并麦克风和摄像头访问权限?
In iOS 7, it was possible to invoke the microphone permission dialog beforehand and see if the permission was granted (see this question, for example). Is there a similar way to invoke the camera permission dialog in iOS 8? Can the dialog be combined for microphone AND camera access permission?
推荐答案
这是我们最终使用的方法:
Here is the approach we ended up using:
if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)]) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
// Will get here on both iOS 7 & 8 even though camera permissions weren't required
// until iOS 8. So for iOS 7 permission will always be granted.
if (granted) {
// Permission has been granted. Use dispatch_async for any UI updating
// code because this block may be executed in a thread.
dispatch_async(dispatch_get_main_queue(), ^{
[self doStuff];
});
} else {
// Permission has been denied.
}
}];
} else {
// We are on iOS <= 6. Just do what we need to do.
[self doStuff];
}
这篇关于在 iOS 8 中呈现相机权限对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!