当我的应用程序在 iOS 8 上第一次尝试访问摄像头时,会向用户显示一个摄像头权限对话框,很像 iOS 7 中用于访问麦克风的麦克风对话框。
在 iOS 7 中,可以预先调用麦克风权限对话框并查看是否授予了权限(请参阅这个问题 https://stackoverflow.com/questions/17081753/how-do-i-request-mic-record-permission-from-user, 例如)。 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];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)