Skip to content

Commit

Permalink
fix(ios): fix openSettings on iOS 10.0 (bitpay#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson authored Feb 14, 2017
1 parent 6799cac commit aaa098c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/ios/QRScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit aaa098c

Please sign in to comment.