当我的应用在 iOS 8 上首次尝试访问摄像头时,用户会看到一个摄像头权限对话框,很像 iOS 7 中用于麦克风访问的麦克风对话框。
在 iOS 7 中,可以预先调用麦克风权限对话框并查看权限是否被授予(例如,参见 this question)。在 iOS 8 中是否有类似的方法来调用相机权限对话框?是否可以将对话框合并为麦克风和摄像头访问权限?
最佳答案
这是我们最终使用的方法:
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 - 在 iOS 8 中呈现相机权限对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25803217/