gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:32:13 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com