From e92723a74cb7051fee793e4850eb1b6407b68e5d Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Tue, 5 Nov 2024 15:41:38 +0100 Subject: [PATCH] ios and macos: forced 'var registrar: FlutterPluginRegistrar' to not be nullable on native side --- .../ios/Classes/CredentialDatabase.swift | 2 +- .../FindInteraction/FindInteractionController.swift | 8 +++----- .../HeadlessInAppWebView/HeadlessInAppWebView.swift | 2 +- .../HeadlessInAppWebViewManager.swift | 2 +- .../ios/Classes/InAppBrowser/InAppBrowserManager.swift | 2 +- .../InAppBrowser/InAppBrowserWebViewController.swift | 4 ++-- .../Classes/InAppWebView/FlutterWebViewController.swift | 8 +++----- .../ios/Classes/InAppWebView/InAppWebViewManager.swift | 2 +- .../InAppWebView/WebMessage/WebMessageChannel.swift | 8 +++----- .../InAppWebView/WebMessage/WebMessageListener.swift | 8 +++----- .../ios/Classes/MyCookieManager.swift | 2 +- .../ios/Classes/MyWebStorageManager.swift | 2 +- flutter_inappwebview_ios/ios/Classes/PlatformUtil.swift | 2 +- .../ios/Classes/PrintJob/PrintJobController.swift | 8 +++----- .../ios/Classes/PullToRefresh/PullToRefreshControl.swift | 8 +++----- .../SafariViewController/ChromeSafariBrowserManager.swift | 2 +- .../SafariViewController/SafariViewController.swift | 4 ++-- .../ios/Classes/SwiftFlutterPlugin.swift | 5 +++-- flutter_inappwebview_ios/ios/Classes/Util.swift | 8 ++++---- .../WebAuthenticationSession.swift | 2 +- .../WebAuthenticationSessionManager.swift | 2 +- .../macos/Classes/CredentialDatabase.swift | 2 +- .../FindInteraction/FindInteractionController.swift | 8 +++----- .../HeadlessInAppWebView/HeadlessInAppWebView.swift | 2 +- .../HeadlessInAppWebViewManager.swift | 2 +- .../macos/Classes/InAppBrowser/InAppBrowserManager.swift | 2 +- .../InAppBrowser/InAppBrowserWebViewController.swift | 4 ++-- .../Classes/InAppWebView/FlutterWebViewController.swift | 8 +++----- .../macos/Classes/InAppWebView/InAppWebViewManager.swift | 2 +- .../InAppWebView/WebMessage/WebMessageChannel.swift | 8 +++----- .../InAppWebView/WebMessage/WebMessageListener.swift | 8 +++----- .../macos/Classes/InAppWebViewFlutterPlugin.swift | 4 ++-- .../macos/Classes/MyCookieManager.swift | 2 +- .../macos/Classes/MyWebStorageManager.swift | 2 +- .../macos/Classes/PlatformUtil.swift | 2 +- .../macos/Classes/PrintJob/PrintJobController.swift | 8 +++----- .../WebAuthenticationSession.swift | 2 +- .../WebAuthenticationSessionManager.swift | 2 +- 38 files changed, 69 insertions(+), 90 deletions(-) diff --git a/flutter_inappwebview_ios/ios/Classes/CredentialDatabase.swift b/flutter_inappwebview_ios/ios/Classes/CredentialDatabase.swift index bc6602441..f76e4fbd2 100755 --- a/flutter_inappwebview_ios/ios/Classes/CredentialDatabase.swift +++ b/flutter_inappwebview_ios/ios/Classes/CredentialDatabase.swift @@ -14,7 +14,7 @@ public class CredentialDatabase: ChannelDelegate { private var plugin: SwiftFlutterPlugin? init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: CredentialDatabase.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: CredentialDatabase.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/FindInteraction/FindInteractionController.swift b/flutter_inappwebview_ios/ios/Classes/FindInteraction/FindInteractionController.swift index 84930c45f..0c4a8723c 100644 --- a/flutter_inappwebview_ios/ios/Classes/FindInteraction/FindInteractionController.swift +++ b/flutter_inappwebview_ios/ios/Classes/FindInteraction/FindInteractionController.swift @@ -54,11 +54,9 @@ public class FindInteractionController: NSObject, Disposable { self.plugin = plugin self.webView = webView self.settings = settings - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: FindInteractionController.METHOD_CHANNEL_NAME_PREFIX + String(describing: id), - binaryMessenger: registrar.messenger()) - self.channelDelegate = FindInteractionChannelDelegate(findInteractionController: self, channel: channel) - } + let channel = FlutterMethodChannel(name: FindInteractionController.METHOD_CHANNEL_NAME_PREFIX + String(describing: id), + binaryMessenger: plugin.registrar.messenger()) + self.channelDelegate = FindInteractionChannelDelegate(findInteractionController: self, channel: channel) } public func prepare() { diff --git a/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift b/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift index 5d13086d7..dffc124da 100644 --- a/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift +++ b/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift @@ -20,7 +20,7 @@ public class HeadlessInAppWebView: Disposable { self.flutterWebView = flutterWebView self.plugin = plugin let channel = FlutterMethodChannel(name: HeadlessInAppWebView.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: plugin.registrar!.messenger()) + binaryMessenger: plugin.registrar.messenger()) self.channelDelegate = HeadlessWebViewChannelDelegate(headlessWebView: self, channel: channel) } diff --git a/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift b/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift index 36d770c36..f0af5906d 100644 --- a/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift @@ -19,7 +19,7 @@ public class HeadlessInAppWebViewManager: ChannelDelegate { var webViews: [String: HeadlessInAppWebView?] = [:] init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: HeadlessInAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: HeadlessInAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserManager.swift b/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserManager.swift index c7c3b8e77..0be2b5734 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserManager.swift @@ -21,7 +21,7 @@ public class InAppBrowserManager: ChannelDelegate { var navControllers: [String: InAppBrowserNavigationController?] = [:] init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: InAppBrowserManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: InAppBrowserManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserWebViewController.swift b/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserWebViewController.swift index befa12ab0..cee45cfa9 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserWebViewController.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppBrowser/InAppBrowserWebViewController.swift @@ -53,11 +53,11 @@ public class InAppBrowserWebViewController: UIViewController, InAppBrowserDelega var menuItems: [InAppBrowserMenuItem] = [] public override func loadView() { - guard let plugin = plugin, let registrar = plugin.registrar else { + guard let plugin = plugin else { return } - let channel = FlutterMethodChannel(name: InAppBrowserWebViewController.METHOD_CHANNEL_NAME_PREFIX + id, binaryMessenger: registrar.messenger()) + let channel = FlutterMethodChannel(name: InAppBrowserWebViewController.METHOD_CHANNEL_NAME_PREFIX + id, binaryMessenger: plugin.registrar.messenger()) channelDelegate = InAppBrowserChannelDelegate(channel: channel) var userScripts: [UserScript] = [] diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/FlutterWebViewController.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/FlutterWebViewController.swift index 9a0d06902..7a2f1f260 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/FlutterWebViewController.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/FlutterWebViewController.swift @@ -44,11 +44,9 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView, Disposable webView = webViewTransport.webView webView!.id = viewId webView!.plugin = plugin - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: InAppWebView.METHOD_CHANNEL_NAME_PREFIX + String(describing: viewId), - binaryMessenger: registrar.messenger()) - webView!.channelDelegate = WebViewChannelDelegate(webView: webView!, channel: channel) - } + let channel = FlutterMethodChannel(name: InAppWebView.METHOD_CHANNEL_NAME_PREFIX + String(describing: viewId), + binaryMessenger: plugin.registrar.messenger()) + webView!.channelDelegate = WebViewChannelDelegate(webView: webView!, channel: channel) webView!.frame = myView!.bounds webView!.contextMenu = contextMenu webView!.initialUserScripts = userScripts diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewManager.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewManager.swift index 942d9567b..e3397d178 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewManager.swift @@ -19,7 +19,7 @@ public class InAppWebViewManager: ChannelDelegate { var windowAutoincrementId: Int64 = 0 init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: InAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: InAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageChannel.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageChannel.swift index 4858751eb..354a62456 100644 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageChannel.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageChannel.swift @@ -19,11 +19,9 @@ public class WebMessageChannel: FlutterMethodCallDelegate { self.id = id self.plugin = plugin super.init() - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: WebMessageChannel.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: registrar.messenger()) - self.channelDelegate = WebMessageChannelChannelDelegate(webMessageChannel: self, channel: channel) - } + let channel = FlutterMethodChannel(name: WebMessageChannel.METHOD_CHANNEL_NAME_PREFIX + id, + binaryMessenger: plugin.registrar.messenger()) + self.channelDelegate = WebMessageChannelChannelDelegate(webMessageChannel: self, channel: channel) self.ports = [ WebMessagePort(name: "port1", index: 0, webMessageChannelId: self.id, webMessageChannel: self), WebMessagePort(name: "port2", index: 1, webMessageChannelId: self.id, webMessageChannel: self) diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageListener.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageListener.swift index eab72b1de..5b42e9bf2 100644 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageListener.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/WebMessage/WebMessageListener.swift @@ -23,11 +23,9 @@ public class WebMessageListener: FlutterMethodCallDelegate { self.jsObjectName = jsObjectName self.allowedOriginRules = allowedOriginRules super.init() - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: WebMessageListener.METHOD_CHANNEL_NAME_PREFIX + self.id + "_" + self.jsObjectName, - binaryMessenger: registrar.messenger()) - self.channelDelegate = WebMessageListenerChannelDelegate(webMessageListener: self, channel: channel) - } + let channel = FlutterMethodChannel(name: WebMessageListener.METHOD_CHANNEL_NAME_PREFIX + self.id + "_" + self.jsObjectName, + binaryMessenger: plugin.registrar.messenger()) + self.channelDelegate = WebMessageListenerChannelDelegate(webMessageListener: self, channel: channel) } public func assertOriginRulesValid() throws { diff --git a/flutter_inappwebview_ios/ios/Classes/MyCookieManager.swift b/flutter_inappwebview_ios/ios/Classes/MyCookieManager.swift index 235d8f9f5..49424d0ad 100755 --- a/flutter_inappwebview_ios/ios/Classes/MyCookieManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/MyCookieManager.swift @@ -16,7 +16,7 @@ public class MyCookieManager: ChannelDelegate { private var plugin: SwiftFlutterPlugin? init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: MyCookieManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: MyCookieManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/MyWebStorageManager.swift b/flutter_inappwebview_ios/ios/Classes/MyWebStorageManager.swift index a375fdfb0..e86b442c4 100755 --- a/flutter_inappwebview_ios/ios/Classes/MyWebStorageManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/MyWebStorageManager.swift @@ -16,7 +16,7 @@ public class MyWebStorageManager: ChannelDelegate { private var plugin: SwiftFlutterPlugin? init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: MyWebStorageManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: MyWebStorageManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/PlatformUtil.swift b/flutter_inappwebview_ios/ios/Classes/PlatformUtil.swift index a44fabc0e..ae5902638 100644 --- a/flutter_inappwebview_ios/ios/Classes/PlatformUtil.swift +++ b/flutter_inappwebview_ios/ios/Classes/PlatformUtil.swift @@ -12,7 +12,7 @@ public class PlatformUtil: ChannelDelegate { var plugin: SwiftFlutterPlugin? init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: PlatformUtil.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: PlatformUtil.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/PrintJob/PrintJobController.swift b/flutter_inappwebview_ios/ios/Classes/PrintJob/PrintJobController.swift index 6b4c3210e..11f689270 100644 --- a/flutter_inappwebview_ios/ios/Classes/PrintJob/PrintJobController.swift +++ b/flutter_inappwebview_ios/ios/Classes/PrintJob/PrintJobController.swift @@ -36,11 +36,9 @@ public class PrintJobController: NSObject, Disposable, UIPrintInteractionControl self.printFormatter = job?.printFormatter self.printPageRenderer = job?.printPageRenderer self.job?.delegate = self - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: PrintJobController.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: registrar.messenger()) - self.channelDelegate = PrintJobChannelDelegate(printJobController: self, channel: channel) - } + let channel = FlutterMethodChannel(name: PrintJobController.METHOD_CHANNEL_NAME_PREFIX + id, + binaryMessenger: plugin.registrar.messenger()) + self.channelDelegate = PrintJobChannelDelegate(printJobController: self, channel: channel) } public func printInteractionControllerWillStartJob(_ printInteractionController: UIPrintInteractionController) { diff --git a/flutter_inappwebview_ios/ios/Classes/PullToRefresh/PullToRefreshControl.swift b/flutter_inappwebview_ios/ios/Classes/PullToRefresh/PullToRefreshControl.swift index 5df23c173..3cf19bfc5 100644 --- a/flutter_inappwebview_ios/ios/Classes/PullToRefresh/PullToRefreshControl.swift +++ b/flutter_inappwebview_ios/ios/Classes/PullToRefresh/PullToRefreshControl.swift @@ -21,11 +21,9 @@ public class PullToRefreshControl: UIRefreshControl, Disposable { super.init() self.plugin = plugin self.settings = settings - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: PullToRefreshControl.METHOD_CHANNEL_NAME_PREFIX + String(describing: id), - binaryMessenger: registrar.messenger()) - self.channelDelegate = PullToRefreshChannelDelegate(pullToRefreshControl: self, channel: channel) - } + let channel = FlutterMethodChannel(name: PullToRefreshControl.METHOD_CHANNEL_NAME_PREFIX + String(describing: id), + binaryMessenger: plugin.registrar.messenger()) + self.channelDelegate = PullToRefreshChannelDelegate(pullToRefreshControl: self, channel: channel) } required init?(coder: NSCoder) { diff --git a/flutter_inappwebview_ios/ios/Classes/SafariViewController/ChromeSafariBrowserManager.swift b/flutter_inappwebview_ios/ios/Classes/SafariViewController/ChromeSafariBrowserManager.swift index 5887ea77e..805d422c9 100755 --- a/flutter_inappwebview_ios/ios/Classes/SafariViewController/ChromeSafariBrowserManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/SafariViewController/ChromeSafariBrowserManager.swift @@ -19,7 +19,7 @@ public class ChromeSafariBrowserManager: ChannelDelegate { var prewarmingTokens: [String: Any?] = [:] init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: ChromeSafariBrowserManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: ChromeSafariBrowserManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_ios/ios/Classes/SafariViewController/SafariViewController.swift b/flutter_inappwebview_ios/ios/Classes/SafariViewController/SafariViewController.swift index 980e983e4..e71fa9827 100755 --- a/flutter_inappwebview_ios/ios/Classes/SafariViewController/SafariViewController.swift +++ b/flutter_inappwebview_ios/ios/Classes/SafariViewController/SafariViewController.swift @@ -26,7 +26,7 @@ public class SafariViewController: SFSafariViewController, SFSafariViewControlle SafariViewController.prepareConfig(configuration: configuration, safariSettings: safariSettings) super.init(url: url, configuration: configuration) let channel = FlutterMethodChannel(name: SafariViewController.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: plugin.registrar!.messenger()) + binaryMessenger: plugin.registrar.messenger()) self.channelDelegate = SafariViewControllerChannelDelegate(safariViewController: self, channel: channel) self.delegate = self } @@ -38,7 +38,7 @@ public class SafariViewController: SFSafariViewController, SFSafariViewControlle self.safariSettings = safariSettings super.init(url: url, entersReaderIfAvailable: entersReaderIfAvailable) let channel = FlutterMethodChannel(name: SafariViewController.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: plugin.registrar!.messenger()) + binaryMessenger: plugin.registrar.messenger()) self.channelDelegate = SafariViewControllerChannelDelegate(safariViewController: self, channel: channel) self.delegate = self } diff --git a/flutter_inappwebview_ios/ios/Classes/SwiftFlutterPlugin.swift b/flutter_inappwebview_ios/ios/Classes/SwiftFlutterPlugin.swift index 22eaecdcd..174714636 100755 --- a/flutter_inappwebview_ios/ios/Classes/SwiftFlutterPlugin.swift +++ b/flutter_inappwebview_ios/ios/Classes/SwiftFlutterPlugin.swift @@ -24,7 +24,7 @@ import SafariServices public class SwiftFlutterPlugin: NSObject, FlutterPlugin { - var registrar: FlutterPluginRegistrar? + var registrar: FlutterPluginRegistrar var platformUtil: PlatformUtil? var inAppWebViewManager: InAppWebViewManager? var myCookieManager: Any? @@ -40,9 +40,10 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { var safariViewControllers: [String: Any?] = [:] public init(with registrar: FlutterPluginRegistrar) { + self.registrar = registrar + super.init() - self.registrar = registrar registrar.register(FlutterWebViewFactory(plugin: self) as FlutterPlatformViewFactory, withId: FlutterWebViewFactory.VIEW_TYPE_ID) platformUtil = PlatformUtil(plugin: self) diff --git a/flutter_inappwebview_ios/ios/Classes/Util.swift b/flutter_inappwebview_ios/ios/Classes/Util.swift index 9992ece9e..25be4af12 100644 --- a/flutter_inappwebview_ios/ios/Classes/Util.swift +++ b/flutter_inappwebview_ios/ios/Classes/Util.swift @@ -12,16 +12,16 @@ var SharedLastTouchPointTimestamp: [InAppWebView: Int64] = [:] public class Util { public static func getUrlAsset(plugin: SwiftFlutterPlugin, assetFilePath: String) throws -> URL { - guard let key = plugin.registrar?.lookupKey(forAsset: assetFilePath), - let assetURL = Bundle.main.url(forResource: key, withExtension: nil) else { + let key = plugin.registrar.lookupKey(forAsset: assetFilePath) + guard let assetURL = Bundle.main.url(forResource: key, withExtension: nil) else { throw NSError(domain: assetFilePath + " asset file cannot be found!", code: 0) } return assetURL } public static func getAbsPathAsset(plugin: SwiftFlutterPlugin, assetFilePath: String) throws -> String { - guard let key = plugin.registrar?.lookupKey(forAsset: assetFilePath), - let assetAbsPath = Bundle.main.path(forResource: key, ofType: nil) else { + let key = plugin.registrar.lookupKey(forAsset: assetFilePath) + guard let assetAbsPath = Bundle.main.path(forResource: key, ofType: nil) else { throw NSError(domain: assetFilePath + " asset file cannot be found!", code: 0) } return assetAbsPath diff --git a/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSession.swift b/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSession.swift index 99409b11d..3f8c32f6d 100644 --- a/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSession.swift +++ b/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSession.swift @@ -37,7 +37,7 @@ public class WebAuthenticationSession: NSObject, ASWebAuthenticationPresentation self.session = SFAuthenticationSession(url: self.url, callbackURLScheme: self.callbackURLScheme, completionHandler: self.completionHandler) } let channel = FlutterMethodChannel(name: WebAuthenticationSession.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: plugin.registrar!.messenger()) + binaryMessenger: plugin.registrar.messenger()) self.channelDelegate = WebAuthenticationSessionChannelDelegate(webAuthenticationSession: self, channel: channel) } diff --git a/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift b/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift index 6ba8238d5..66eff8523 100644 --- a/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift +++ b/flutter_inappwebview_ios/ios/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift @@ -18,7 +18,7 @@ public class WebAuthenticationSessionManager: ChannelDelegate { var sessions: [String: WebAuthenticationSession?] = [:] init(plugin: SwiftFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: WebAuthenticationSessionManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger())) + super.init(channel: FlutterMethodChannel(name: WebAuthenticationSessionManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger())) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/CredentialDatabase.swift b/flutter_inappwebview_macos/macos/Classes/CredentialDatabase.swift index c11ac05b1..4a7a45df7 100755 --- a/flutter_inappwebview_macos/macos/Classes/CredentialDatabase.swift +++ b/flutter_inappwebview_macos/macos/Classes/CredentialDatabase.swift @@ -14,7 +14,7 @@ public class CredentialDatabase: ChannelDelegate { static var credentialStore = URLCredentialStorage.shared init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: CredentialDatabase.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: CredentialDatabase.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/FindInteraction/FindInteractionController.swift b/flutter_inappwebview_macos/macos/Classes/FindInteraction/FindInteractionController.swift index 91602f18b..f6e5492a8 100644 --- a/flutter_inappwebview_macos/macos/Classes/FindInteraction/FindInteractionController.swift +++ b/flutter_inappwebview_macos/macos/Classes/FindInteraction/FindInteractionController.swift @@ -24,11 +24,9 @@ public class FindInteractionController: NSObject, Disposable { self.plugin = plugin self.webView = webView self.settings = settings - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: FindInteractionController.METHOD_CHANNEL_NAME_PREFIX + String(describing: id), - binaryMessenger: registrar.messenger) - self.channelDelegate = FindInteractionChannelDelegate(findInteractionController: self, channel: channel) - } + let channel = FlutterMethodChannel(name: FindInteractionController.METHOD_CHANNEL_NAME_PREFIX + String(describing: id), + binaryMessenger: plugin.registrar.messenger) + self.channelDelegate = FindInteractionChannelDelegate(findInteractionController: self, channel: channel) } public func prepare() { diff --git a/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift b/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift index b95222fb1..9f5b9524f 100644 --- a/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift +++ b/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift @@ -20,7 +20,7 @@ public class HeadlessInAppWebView: Disposable { self.flutterWebView = flutterWebView self.plugin = plugin let channel = FlutterMethodChannel(name: HeadlessInAppWebView.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: plugin.registrar!.messenger) + binaryMessenger: plugin.registrar.messenger) self.channelDelegate = HeadlessWebViewChannelDelegate(headlessWebView: self, channel: channel) } diff --git a/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift b/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift index 29bed518c..4dcd1b536 100644 --- a/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift +++ b/flutter_inappwebview_macos/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebViewManager.swift @@ -19,7 +19,7 @@ public class HeadlessInAppWebViewManager: ChannelDelegate { var webViews: [String: HeadlessInAppWebView?] = [:] init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: HeadlessInAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: HeadlessInAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserManager.swift b/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserManager.swift index 9f3d5c53a..68745e207 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserManager.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserManager.swift @@ -19,7 +19,7 @@ public class InAppBrowserManager: ChannelDelegate { var plugin: InAppWebViewFlutterPlugin? init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: InAppBrowserManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: InAppBrowserManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserWebViewController.swift b/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserWebViewController.swift index 48b16e936..890f154e3 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserWebViewController.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppBrowser/InAppBrowserWebViewController.swift @@ -33,11 +33,11 @@ public class InAppBrowserWebViewController: NSViewController, InAppBrowserDelega var isHidden = false public override func loadView() { - guard let plugin = plugin, let registrar = plugin.registrar else { + guard let plugin = plugin else { return } - let channel = FlutterMethodChannel(name: InAppBrowserWebViewController.METHOD_CHANNEL_NAME_PREFIX + id, binaryMessenger: registrar.messenger) + let channel = FlutterMethodChannel(name: InAppBrowserWebViewController.METHOD_CHANNEL_NAME_PREFIX + id, binaryMessenger: plugin.registrar.messenger) channelDelegate = InAppBrowserChannelDelegate(channel: channel) var userScripts: [UserScript] = [] diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/FlutterWebViewController.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/FlutterWebViewController.swift index 2caa19c6e..04895703f 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/FlutterWebViewController.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/FlutterWebViewController.swift @@ -39,11 +39,9 @@ public class FlutterWebViewController: NSView, Disposable { webView = webViewTransport.webView webView!.id = viewId webView!.plugin = plugin - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: InAppWebView.METHOD_CHANNEL_NAME_PREFIX + String(describing: viewId), - binaryMessenger: registrar.messenger) - webView!.channelDelegate = WebViewChannelDelegate(webView: webView!, channel: channel) - } + let channel = FlutterMethodChannel(name: InAppWebView.METHOD_CHANNEL_NAME_PREFIX + String(describing: viewId), + binaryMessenger: plugin.registrar.messenger) + webView!.channelDelegate = WebViewChannelDelegate(webView: webView!, channel: channel) webView!.frame = self.bounds webView!.initialUserScripts = userScripts } else { diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewManager.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewManager.swift index fa005cfa7..d4d369bd6 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewManager.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewManager.swift @@ -20,7 +20,7 @@ public class InAppWebViewManager: ChannelDelegate { var windowAutoincrementId: Int64 = 0 init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: InAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: InAppWebViewManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageChannel.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageChannel.swift index 63f31fa66..76deada77 100644 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageChannel.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageChannel.swift @@ -20,11 +20,9 @@ public class WebMessageChannel: FlutterMethodCallDelegate { self.id = id self.plugin = plugin super.init() - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: WebMessageChannel.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: registrar.messenger) - self.channelDelegate = WebMessageChannelChannelDelegate(webMessageChannel: self, channel: channel) - } + let channel = FlutterMethodChannel(name: WebMessageChannel.METHOD_CHANNEL_NAME_PREFIX + id, + binaryMessenger: plugin.registrar.messenger) + self.channelDelegate = WebMessageChannelChannelDelegate(webMessageChannel: self, channel: channel) self.ports = [ WebMessagePort(name: "port1", index: 0, webMessageChannelId: self.id, webMessageChannel: self), WebMessagePort(name: "port2", index: 1, webMessageChannelId: self.id, webMessageChannel: self) diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageListener.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageListener.swift index 619619c08..782861b82 100644 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageListener.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/WebMessage/WebMessageListener.swift @@ -24,11 +24,9 @@ public class WebMessageListener: FlutterMethodCallDelegate { self.jsObjectName = jsObjectName self.allowedOriginRules = allowedOriginRules super.init() - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: WebMessageListener.METHOD_CHANNEL_NAME_PREFIX + self.id + "_" + self.jsObjectName, - binaryMessenger: registrar.messenger) - self.channelDelegate = WebMessageListenerChannelDelegate(webMessageListener: self, channel: channel) - } + let channel = FlutterMethodChannel(name: WebMessageListener.METHOD_CHANNEL_NAME_PREFIX + self.id + "_" + self.jsObjectName, + binaryMessenger: plugin.registrar.messenger) + self.channelDelegate = WebMessageListenerChannelDelegate(webMessageListener: self, channel: channel) } public func assertOriginRulesValid() throws { diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebViewFlutterPlugin.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebViewFlutterPlugin.swift index 530efdd79..7248b6045 100644 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebViewFlutterPlugin.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebViewFlutterPlugin.swift @@ -25,7 +25,7 @@ import SafariServices public class InAppWebViewFlutterPlugin: NSObject, FlutterPlugin { - var registrar: FlutterPluginRegistrar? + var registrar: FlutterPluginRegistrar var platformUtil: PlatformUtil? var inAppWebViewManager: InAppWebViewManager? var myCookieManager: Any? @@ -40,8 +40,8 @@ public class InAppWebViewFlutterPlugin: NSObject, FlutterPlugin { var safariViewControllers: [String: Any?] = [:] public init(with registrar: FlutterPluginRegistrar) { - super.init() self.registrar = registrar + super.init() registrar.register(FlutterWebViewFactory(plugin: self) as FlutterPlatformViewFactory, withId: FlutterWebViewFactory.VIEW_TYPE_ID) platformUtil = PlatformUtil(plugin: self) diff --git a/flutter_inappwebview_macos/macos/Classes/MyCookieManager.swift b/flutter_inappwebview_macos/macos/Classes/MyCookieManager.swift index 86e62d7ef..856ac1a25 100755 --- a/flutter_inappwebview_macos/macos/Classes/MyCookieManager.swift +++ b/flutter_inappwebview_macos/macos/Classes/MyCookieManager.swift @@ -16,7 +16,7 @@ public class MyCookieManager: ChannelDelegate { static var httpCookieStore = WKWebsiteDataStore.default().httpCookieStore init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: MyCookieManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: MyCookieManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/MyWebStorageManager.swift b/flutter_inappwebview_macos/macos/Classes/MyWebStorageManager.swift index a20b46e6a..c77840bbb 100755 --- a/flutter_inappwebview_macos/macos/Classes/MyWebStorageManager.swift +++ b/flutter_inappwebview_macos/macos/Classes/MyWebStorageManager.swift @@ -15,7 +15,7 @@ public class MyWebStorageManager: ChannelDelegate { static var websiteDataStore = WKWebsiteDataStore.default() init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: MyWebStorageManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: MyWebStorageManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/PlatformUtil.swift b/flutter_inappwebview_macos/macos/Classes/PlatformUtil.swift index a349a908f..20f96e9cf 100644 --- a/flutter_inappwebview_macos/macos/Classes/PlatformUtil.swift +++ b/flutter_inappwebview_macos/macos/Classes/PlatformUtil.swift @@ -13,7 +13,7 @@ public class PlatformUtil: ChannelDelegate { var plugin: InAppWebViewFlutterPlugin? init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: PlatformUtil.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: PlatformUtil.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin } diff --git a/flutter_inappwebview_macos/macos/Classes/PrintJob/PrintJobController.swift b/flutter_inappwebview_macos/macos/Classes/PrintJob/PrintJobController.swift index 9b76a4085..bbca38dd3 100644 --- a/flutter_inappwebview_macos/macos/Classes/PrintJob/PrintJobController.swift +++ b/flutter_inappwebview_macos/macos/Classes/PrintJob/PrintJobController.swift @@ -36,11 +36,9 @@ public class PrintJobController: NSObject, Disposable { super.init() self.job = job self.settings = settings - if let registrar = plugin.registrar { - let channel = FlutterMethodChannel(name: PrintJobController.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: registrar.messenger) - self.channelDelegate = PrintJobChannelDelegate(printJobController: self, channel: channel) - } + let channel = FlutterMethodChannel(name: PrintJobController.METHOD_CHANNEL_NAME_PREFIX + id, + binaryMessenger: plugin.registrar.messenger) + self.channelDelegate = PrintJobChannelDelegate(printJobController: self, channel: channel) } public func present(parentWindow: NSWindow? = nil, completionHandler: PrintJobController.CompletionHandler? = nil) { diff --git a/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSession.swift b/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSession.swift index 92140fe1e..c314423bf 100644 --- a/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSession.swift +++ b/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSession.swift @@ -34,7 +34,7 @@ public class WebAuthenticationSession: NSObject, ASWebAuthenticationPresentation self.session = session } let channel = FlutterMethodChannel(name: WebAuthenticationSession.METHOD_CHANNEL_NAME_PREFIX + id, - binaryMessenger: plugin.registrar!.messenger) + binaryMessenger: plugin.registrar.messenger) self.channelDelegate = WebAuthenticationSessionChannelDelegate(webAuthenticationSession: self, channel: channel) } diff --git a/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift b/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift index 102438fff..fb153f84a 100644 --- a/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift +++ b/flutter_inappwebview_macos/macos/Classes/WebAuthenticationSession/WebAuthenticationSessionManager.swift @@ -18,7 +18,7 @@ public class WebAuthenticationSessionManager: ChannelDelegate { var sessions: [String: WebAuthenticationSession?] = [:] init(plugin: InAppWebViewFlutterPlugin) { - super.init(channel: FlutterMethodChannel(name: WebAuthenticationSessionManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar!.messenger)) + super.init(channel: FlutterMethodChannel(name: WebAuthenticationSessionManager.METHOD_CHANNEL_NAME, binaryMessenger: plugin.registrar.messenger)) self.plugin = plugin }