From 5fb22b0e89983ad09e0d5440e0404fc1b3793463 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 27 Mar 2022 23:00:53 -0700 Subject: [PATCH] Version guard some os_log calls While the latest Cordova iOS doesn't support lower than iOS 11, this plugin strives to remain compatible with older iOS versions. --- src/ios/OAuthPlugin.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ios/OAuthPlugin.swift b/src/ios/OAuthPlugin.swift index a0f1a25..5f06715 100644 --- a/src/ios/OAuthPlugin.swift +++ b/src/ios/OAuthPlugin.swift @@ -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(_:)), @@ -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) @@ -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) + } } }