gpt4 book ai didi

ios - 在 iPad 上请求相机权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:36 25 4
gpt4 key购买 nike

在一个应用程序中,我目前只有在检查相机权限后才能拍照,如下所示:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized) {
// Take picture
}else{
// Prompt user to go into their settings and add permissions for app
}

但是,在首次使用时,a) 最初的“您愿意授予此应用摄像头权限吗?”提示不会出现,并且 b) 该应用程序不会出现在 iPad 的设置中的隐私 -> 相机下。这导致了无法在应用程序中允许相机权限的不幸情况。

任何关于如何避免这种情况的建议将不胜感激。感谢阅读。

最佳答案

您需要使用以下代码请求权限:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
// Take picture
}
else
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
{
if (granted)
{
NSLog(@"User Granted");
}
else
{
NSLog(@"User Denied");
}
}];
}

关于ios - 在 iPad 上请求相机权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27726452/

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