diff --git a/src/ios/QRScanner.swift b/src/ios/QRScanner.swift index a1b9f8e4..95df5b50 100644 --- a/src/ios/QRScanner.swift +++ b/src/ios/QRScanner.swift @@ -422,12 +422,26 @@ class QRScanner : CDVPlugin, AVCaptureMetadataOutputObjectsDelegate { commandDelegate!.send(pluginResult, callbackId:command.callbackId) } - func openSettings(command: CDVInvokedUrlCommand) { - if #available(iOS 8.0, *) { - UIApplication.shared.openURL(NSURL(string: UIApplicationOpenSettingsURLString)! as URL) - self.getStatus(command) + func openSettings(_ command: CDVInvokedUrlCommand) { + if #available(iOS 10.0, *) { + guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else { + return + } + if UIApplication.shared.canOpenURL(settingsUrl) { + UIApplication.shared.open(settingsUrl, completionHandler: { (success) in + self.getStatus(command) + }) } else { self.sendErrorCode(command: command, error: QRScannerError.OPEN_SETTINGS_UNAVAILABLE) + } + } else { + // pre iOS 10.0 + if #available(iOS 8.0, *) { + UIApplication.shared.openURL(NSURL(string: UIApplicationOpenSettingsURLString)! as URL) + self.getStatus(command) + } else { + self.sendErrorCode(command: command, error: QRScannerError.OPEN_SETTINGS_UNAVAILABLE) + } } } }