问题在于: 有两个UIViewControllers:" WelcomeScreen"例如," FailScreen"。 第一个上有一个Camera Access Request。 用户点击"不允许"和FailScreen打开。 ......然后崩溃了。
代码:
AVCaptureDevice.requestAccess(for: .video) { (answer: Bool) in
print("Camera access request.")
if answer {
print("Camera access autorized.")
// Continue to Notifications Request...
}
else {
print("Camera access denied.")
self.present(FailureViewController(), animated: true, completion: nil)
}
控制台:
Camera access denied.
libc++abi.dylib: terminating with uncaught exception of type NSException
有人可以告诉我,如何修复它?谢谢。
答案 0 :(得分:0)
我希望这会对你有所帮助。
首先,您应该在Info.plist中为Privacy - Camera Usage Description
键添加值,并了解下面的代码
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (success) in
if success {
print("The user granted permission")
} else {
print("put up an alert telling the user the camera is not available")
DispatchQueue.main.async(execute: { () -> Void in
let ac = UIAlertController(title: "Camera Error", message: "For some reason, the camera in this device is not accepting your authorization. Check with your device supplier.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
self.present(ac, animated: true, completion: nil)
})//back on main queue block
}//if success
})//requestAccessForMediaType block
}//switch
} else {//if device has a camera
let ac = UIAlertController(title: "Source not available.", message: "The camera is not available.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
present(ac, animated: true, completion: nil)
}//if camera is no else
}