ios - 在 iOS 8 中呈现相机权限对话框

标签 ios permissions camera ios8 ios-permissions

当我的应用在 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/

相关文章:

ios - 在 iOS 中考虑 alpha 部分在另一个图像上添加图像

ios - 可以在 UICollectionView 中自定义单元格吗?

iOS : How to get song id using echonest Api

postgresql - 锁定 PostgreSQL 中的公共(public)组角色

bash - 我如何使用 su 作为该用户执行 bash 脚本的其余部分?

android - 多相机组件react-native-camera

c - bash : ./comp.out:权限被拒绝

android - 将位图设置为 ImageView onActivityResult 不显示任何内容

android - 如何在 fragment 中再次初始化相机?

android - 在 webrtc 中使用 MediaDevices.getUserMedia() 切换摄像头