gpt4 book ai didi

ios - 在 Swift 2.0 中检查权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:03:34 26 4
gpt4 key购买 nike

无论我在哪里添加代码来检查相机/麦克风/照片等权限,弹出确认总是会终止我的应用程序或向我发送一些 View Controller 。

示例如下。

当我有一个处理权限的页面时,我几乎没有 View Controller (通过注册过程的一部分)。用户点击一个按钮来处理使用以下代码的相机权限。

if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) !=  AVAuthorizationStatus.Authorized {
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
if granted == true {
// do something
} else {
// determine whether not determined, denied etc and do something else
}
});
}

然而,一旦弹出 iOS 确认消息,它就会将应用程序抛回 2 个 View Controller 。在其他情况下(例如在 viewDidLoad 上)权限请求会在做出选择后立即终止应用。

有什么想法我在我的设置中遗漏了什么或如何防止这种行为吗?

谢谢。

最佳答案

我想你误解了我的评论,我的意思是

if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) !=  AVAuthorizationStatus.Authorized { // here you are checking if it's not authorized i..e  it's denied, NotDetermined or Restricted
....
}
else if if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) == AVAuthorizationStatus.Authorized
// do the something in case it's autorized

我在这里列出 key -

     <key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>

关于ios - 在 Swift 2.0 中检查权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39848771/

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