From 5e15dbb4800745b3e547108d70f4caf539d19b79 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 927f1c3..241a405 100644 --- a/src/ios/OAuthPlugin.swift +++ b/src/ios/OAuthPlugin.swift @@ -127,7 +127,9 @@ class OAuthPlugin : CDVPlugin, SFSafariViewControllerDelegate, ASWebAuthenticati let urlScheme = self.commandDelegate.settings["oauthscheme"] as! String self.callbackScheme = "\(urlScheme)://oauth_callback" - self.logger = OSLog(subsystem: urlScheme, category: "Cordova") + if #available(iOS 10.0, *) { + self.logger = OSLog(subsystem: urlScheme, 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) + } } }