在 iOS 8 中显示相机权限对话框 [英] Presenting camera permission dialog in iOS 8

查看:16
本文介绍了在 iOS 8 中显示相机权限对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用第一次尝试在 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 中显示相机权限对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆