Skip to content

Commit

Permalink
Version guard some os_log calls
Browse files Browse the repository at this point in the history
While the latest Cordova iOS doesn't support lower than iOS 11, this
plugin strives to remain compatible with older iOS versions.
  • Loading branch information
dpogue committed Mar 29, 2022
1 parent 26e82c5 commit 5fb22b0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ios/OAuthPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class OAuthPlugin : CDVPlugin, SFSafariViewControllerDelegate, ASWebAuthenticati
let appID = Bundle.main.bundleIdentifier!

self.callbackScheme = "\(appID)://oauth_callback"
self.logger = OSLog(subsystem: appID, category: "Cordova")
if #available(iOS 10.0, *) {
self.logger = OSLog(subsystem: appID, category: "Cordova")
}

NotificationCenter.default.addObserver(self,
selector: #selector(OAuthPlugin._handleOpenURL(_:)),
Expand Down Expand Up @@ -186,7 +188,11 @@ class OAuthPlugin : CDVPlugin, SFSafariViewControllerDelegate, ASWebAuthenticati
jsobj[$0.name] = $0.value
}

os_log("OAuth called back with parameters.", log: self.logger!, type: .info)
if #available(iOS 10.0, *) {
os_log("OAuth called back with parameters.", log: self.logger!, type: .info)
} else {
NSLog("OAuth called back with parameters.")
}

do {
let data = try JSONSerialization.data(withJSONObject: jsobj)
Expand All @@ -195,7 +201,11 @@ class OAuthPlugin : CDVPlugin, SFSafariViewControllerDelegate, ASWebAuthenticati
self.webViewEngine.evaluateJavaScript("window.dispatchEvent(new MessageEvent('message', { data: 'oauth::\(msg)' }));", completionHandler: nil)
} catch {
let errStr = "JSON Serialization failed: \(error)"
os_log("%@", log: self.logger!, type: .error, errStr)
if #available(iOS 10.0, *) {
os_log("%@", log: self.logger!, type: .error, errStr)
} else {
NSLog(errStr)
}
}
}

Expand Down

0 comments on commit 5fb22b0

Please sign in to comment.