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

查看:552
本文介绍了在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天全站免登陆