无论我在哪里添加代码来检查相机/麦克风/照片等权限,弹出确认总是会杀死我的应用程序或给我发回几个视图控制器。
示例如下:
当我有一个处理权限的页面时,我有几个视图控制器(通过注册过程的一部分)。用户点击一个按钮来处理使用以下代码的相机权限。
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个视图控制器。在其他情况下(例如在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>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>