yannickl/QRCodeReader.swift

Crash when camera permission is denied. * I am using tag '7.5.0' because of my current swift version

mhmdrmdn94 opened this issue · 1 comments

Crash when camera permission is denied. * I am using tag '7.5.0' because of my current swift version

This is a normal behaviour, you must check before whether the permission are valid, like in the example project:

private func checkScanPermissions() -> Bool {
do {
return try QRCodeReader.supportsMetadataObjectTypes()
} catch let error as NSError {
let alert: UIAlertController
switch error.code {
case -11852:
alert = UIAlertController(title: "Error", message: "This app is not authorized to use Back Camera.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Setting", style: .default, handler: { (_) in
DispatchQueue.main.async {
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.openURL(settingsURL)
}
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
default:
alert = UIAlertController(title: "Error", message: "Reader not supported by the current device", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
}
present(alert, animated: true, completion: nil)
return false
}
}