From 564800187be8a339f55a817f6fae755d7b75c400 Mon Sep 17 00:00:00 2001 From: Robert Constantinescu Date: Tue, 19 Nov 2019 13:38:36 +0200 Subject: [PATCH] - added a shared WKProcessPool for webview instances --- ios/Classes/FlutterWebViewController.swift | 2 +- ios/Classes/InAppBrowserWebViewController.swift | 2 +- ios/Classes/InAppWebView.swift | 3 ++- ios/Classes/SwiftFlutterPlugin.swift | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ios/Classes/FlutterWebViewController.swift b/ios/Classes/FlutterWebViewController.swift index c63154576..ce17e657f 100644 --- a/ios/Classes/FlutterWebViewController.swift +++ b/ios/Classes/FlutterWebViewController.swift @@ -28,7 +28,7 @@ public class FlutterWebViewController: NSObject, FlutterPlatformView { let options = InAppWebViewOptions() options.parse(options: initialOptions) - let preWebviewConfiguration = InAppWebView.preWKWebViewConfiguration(options: options) + let preWebviewConfiguration = InAppWebView.preWKWebViewConfiguration(options: options, webViewProcessPool: SwiftFlutterPlugin.webViewProcessPool) webView = InAppWebView(frame: frame, configuration: preWebviewConfiguration, IABController: nil, IAWController: self) let channelName = "com.pichillilorenzo/flutter_inappwebview_" + String(viewId) diff --git a/ios/Classes/InAppBrowserWebViewController.swift b/ios/Classes/InAppBrowserWebViewController.swift index a9f187267..8a75690a4 100644 --- a/ios/Classes/InAppBrowserWebViewController.swift +++ b/ios/Classes/InAppBrowserWebViewController.swift @@ -113,7 +113,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU override func viewWillAppear(_ animated: Bool) { if !viewPrepared { - let preWebviewConfiguration = InAppWebView.preWKWebViewConfiguration(options: webViewOptions) + let preWebviewConfiguration = InAppWebView.preWKWebViewConfiguration(options: webViewOptions, webViewProcessPool: SwiftFlutterPlugin.webViewProcessPool) self.webView = InAppWebView(frame: .zero, configuration: preWebviewConfiguration, IABController: self, IAWController: nil) self.containerWebView.addSubview(self.webView) prepareConstraints() diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift index ee27192e8..5e637a0b4 100644 --- a/ios/Classes/InAppWebView.swift +++ b/ios/Classes/InAppWebView.swift @@ -191,8 +191,9 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi } } - public static func preWKWebViewConfiguration(options: InAppWebViewOptions?) -> WKWebViewConfiguration { + public static func preWKWebViewConfiguration(options: InAppWebViewOptions?, webViewProcessPool: WKProcessPool) -> WKWebViewConfiguration { let configuration = WKWebViewConfiguration() + configuration.processPool = webViewProcessPool if #available(iOS 10.0, *) { configuration.mediaTypesRequiringUserActionForPlayback = ((options?.mediaPlaybackRequiresUserGesture)!) ? .all : [] diff --git a/ios/Classes/SwiftFlutterPlugin.swift b/ios/Classes/SwiftFlutterPlugin.swift index e2f9a80b3..5a3040aba 100644 --- a/ios/Classes/SwiftFlutterPlugin.swift +++ b/ios/Classes/SwiftFlutterPlugin.swift @@ -38,6 +38,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { static var registrar: FlutterPluginRegistrar? static var channel: FlutterMethodChannel? + static let webViewProcessPool: WKProcessPool = WKProcessPool() var webViewControllers: [String: InAppBrowserWebViewController?] = [:] var safariViewControllers: [String: Any?] = [:]