Commit 8b5a6347 authored by pichillilorenzo's avatar pichillilorenzo

working on iOS inline webview implementation

parent a5a784dd
This diff is collapsed.
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key></key>
<string></string>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>
<dict> <dict>
<key>NSAllowsLocalNetworking</key> <key>NSAllowsLocalNetworking</key>
...@@ -44,6 +46,8 @@ ...@@ -44,6 +46,8 @@
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
</dict> </dict>
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.dart_tool" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.pub" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/build" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/ios/Flutter/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" />
</content> </content>
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
......
This diff is collapsed.
...@@ -130,9 +130,9 @@ func convertToDictionary(text: String) -> [String: Any]? { ...@@ -130,9 +130,9 @@ func convertToDictionary(text: String) -> [String: Any]? {
//} //}
class InAppWebView_IBWrapper: InAppWebView { class InAppWebView_IBWrapper: InAppWebView {
required convenience init?(coder: NSCoder) { required convenience init(coder: NSCoder) {
let config = WKWebViewConfiguration() let config = WKWebViewConfiguration()
self.init(frame: .zero, configuration: config) self.init(frame: .zero, configuration: config, IABController: nil, IAWController: nil)
self.translatesAutoresizingMaskIntoConstraints = false self.translatesAutoresizingMaskIntoConstraints = false
} }
} }
...@@ -176,6 +176,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU ...@@ -176,6 +176,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
self.webView.IABController = self
if !viewPrepared { if !viewPrepared {
prepareConstraints() prepareConstraints()
prepareWebView() prepareWebView()
......
This diff is collapsed.
...@@ -36,7 +36,7 @@ extension Dictionary where Key: ExpressibleByStringLiteral { ...@@ -36,7 +36,7 @@ extension Dictionary where Key: ExpressibleByStringLiteral {
public class SwiftFlutterPlugin: NSObject, FlutterPlugin { public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
static var registrar: FlutterPluginRegistrar? static var registrar: FlutterPluginRegistrar?
var channel: FlutterMethodChannel static var channel: FlutterMethodChannel?
var webViewControllers: [String: InAppBrowserWebViewController?] = [:] var webViewControllers: [String: InAppBrowserWebViewController?] = [:]
var safariViewControllers: [String: Any?] = [:] var safariViewControllers: [String: Any?] = [:]
...@@ -45,7 +45,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -45,7 +45,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
private var previousStatusBarStyle = -1 private var previousStatusBarStyle = -1
public init(with registrar: FlutterPluginRegistrar) { public init(with registrar: FlutterPluginRegistrar) {
channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser", binaryMessenger: registrar.messenger()) SwiftFlutterPlugin.channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser", binaryMessenger: registrar.messenger())
} }
public static func register(with registrar: FlutterPluginRegistrar) { public static func register(with registrar: FlutterPluginRegistrar) {
...@@ -220,14 +220,14 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -220,14 +220,14 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
} }
break break
case "setOptions": case "setOptions":
let optionsType = arguments!["optionsType"] as! String; let optionsType = arguments!["optionsType"] as! String
switch (optionsType){ switch (optionsType){
case "InAppBrowserOptions": case "InAppBrowserOptions":
let inAppBrowserOptions = InAppBrowserOptions(); let inAppBrowserOptions = InAppBrowserOptions()
let inAppBroeserOptionsMap = arguments!["options"] as! [String: Any]; let inAppBrowserOptionsMap = arguments!["options"] as! [String: Any]
inAppBrowserOptions.parse(options: inAppBroeserOptionsMap); inAppBrowserOptions.parse(options: inAppBrowserOptionsMap)
self.setOptions(uuid: uuid, options: inAppBrowserOptions, optionsMap: inAppBroeserOptionsMap); self.setOptions(uuid: uuid, options: inAppBrowserOptions, optionsMap: inAppBrowserOptionsMap)
break; break
default: default:
result(FlutterError(code: "InAppBrowserFlutterPlugin", message: "Options " + optionsType + " not available.", details: nil)) result(FlutterError(code: "InAppBrowserFlutterPlugin", message: "Options " + optionsType + " not available.", details: nil))
} }
...@@ -237,8 +237,8 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -237,8 +237,8 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
result(self.getOptions(uuid: uuid)) result(self.getOptions(uuid: uuid))
break break
case "getCopyBackForwardList": case "getCopyBackForwardList":
result(self.getCopyBackForwardList(uuid: uuid)); result(self.getCopyBackForwardList(uuid: uuid))
break; break
default: default:
result(FlutterMethodNotImplemented) result(FlutterMethodNotImplemented)
break break
...@@ -279,7 +279,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -279,7 +279,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
let optionsFallback = (arguments["optionsFallback"] as? [String: Any])! let optionsFallback = (arguments["optionsFallback"] as? [String: Any])!
open(uuid: uuid, uuidFallback: uuidFallback, inAppBrowser: absoluteUrl!, headers: headers, withOptions: safariOptions, useChromeSafariBrowser: true, withOptionsFallback: optionsFallback, result: result); open(uuid: uuid, uuidFallback: uuidFallback, inAppBrowser: absoluteUrl!, headers: headers, withOptions: safariOptions, useChromeSafariBrowser: true, withOptionsFallback: optionsFallback, result: result)
} }
else { else {
let options = (arguments["options"] as? [String: Any])! let options = (arguments["options"] as? [String: Any])!
...@@ -702,21 +702,21 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -702,21 +702,21 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
func onBrowserCreated(uuid: String, webView: WKWebView) { func onBrowserCreated(uuid: String, webView: WKWebView) {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
channel.invokeMethod("onBrowserCreated", arguments: ["uuid": uuid]) SwiftFlutterPlugin.channel!.invokeMethod("onBrowserCreated", arguments: ["uuid": uuid])
} }
} }
func onLoadStart(uuid: String, webView: WKWebView) { func onLoadStart(uuid: String, webView: WKWebView) {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
let url: String = webViewController!.currentURL!.absoluteString let url: String = webViewController!.currentURL!.absoluteString
channel.invokeMethod("onLoadStart", arguments: ["uuid": uuid, "url": url]) SwiftFlutterPlugin.channel!.invokeMethod("onLoadStart", arguments: ["uuid": uuid, "url": url])
} }
} }
func onLoadStop(uuid: String, webView: WKWebView) { func onLoadStop(uuid: String, webView: WKWebView) {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
let url: String = webViewController!.currentURL!.absoluteString let url: String = webViewController!.currentURL!.absoluteString
channel.invokeMethod("onLoadStop", arguments: ["uuid": uuid, "url": url]) SwiftFlutterPlugin.channel!.invokeMethod("onLoadStop", arguments: ["uuid": uuid, "url": url])
} }
} }
...@@ -724,13 +724,13 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -724,13 +724,13 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
let url: String = webViewController!.currentURL!.absoluteString let url: String = webViewController!.currentURL!.absoluteString
let arguments = ["uuid": uuid, "url": url, "code": error._code, "message": error.localizedDescription] as [String : Any] let arguments = ["uuid": uuid, "url": url, "code": error._code, "message": error.localizedDescription] as [String : Any]
channel.invokeMethod("onLoadError", arguments: arguments) SwiftFlutterPlugin.channel!.invokeMethod("onLoadError", arguments: arguments)
} }
} }
func onProgressChanged(uuid: String, webView: WKWebView, progress: Int) { func onProgressChanged(uuid: String, webView: WKWebView, progress: Int) {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
channel.invokeMethod("onProgressChanged", arguments: ["uuid": uuid, "progress": progress]) SwiftFlutterPlugin.channel!.invokeMethod("onProgressChanged", arguments: ["uuid": uuid, "progress": progress])
} }
} }
...@@ -758,50 +758,50 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -758,50 +758,50 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
"method": request!.httpMethod! "method": request!.httpMethod!
] ]
] ]
channel.invokeMethod("onLoadResource", arguments: arguments) SwiftFlutterPlugin.channel!.invokeMethod("onLoadResource", arguments: arguments)
} }
} }
func onScrollChanged(uuid: String, webView: WKWebView, x: Int, y: Int) { func onScrollChanged(uuid: String, webView: WKWebView, x: Int, y: Int) {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
channel.invokeMethod("onScrollChanged", arguments: ["uuid": uuid, "x": x, "y": y]) SwiftFlutterPlugin.channel!.invokeMethod("onScrollChanged", arguments: ["uuid": uuid, "x": x, "y": y])
} }
} }
func onExit(uuid: String) { func onExit(uuid: String) {
channel.invokeMethod("onExit", arguments: ["uuid": uuid]) SwiftFlutterPlugin.channel!.invokeMethod("onExit", arguments: ["uuid": uuid])
} }
func shouldOverrideUrlLoading(uuid: String, webView: WKWebView, url: URL) { func shouldOverrideUrlLoading(uuid: String, webView: WKWebView, url: URL) {
if self.webViewControllers[uuid] != nil { if self.webViewControllers[uuid] != nil {
channel.invokeMethod("shouldOverrideUrlLoading", arguments: ["uuid": uuid, "url": url.absoluteString]) SwiftFlutterPlugin.channel!.invokeMethod("shouldOverrideUrlLoading", arguments: ["uuid": uuid, "url": url.absoluteString])
} }
} }
func onConsoleMessage(uuid: String, sourceURL: String, lineNumber: Int, message: String, messageLevel: String) { func onConsoleMessage(uuid: String, sourceURL: String, lineNumber: Int, message: String, messageLevel: String) {
if self.webViewControllers[uuid] != nil { if self.webViewControllers[uuid] != nil {
channel.invokeMethod("onConsoleMessage", arguments: ["uuid": uuid, "sourceURL": sourceURL, "lineNumber": lineNumber, "message": message, "messageLevel": messageLevel]) SwiftFlutterPlugin.channel!.invokeMethod("onConsoleMessage", arguments: ["uuid": uuid, "sourceURL": sourceURL, "lineNumber": lineNumber, "message": message, "messageLevel": messageLevel])
} }
} }
func onChromeSafariBrowserOpened(uuid: String) { func onChromeSafariBrowserOpened(uuid: String) {
if self.safariViewControllers[uuid] != nil { if self.safariViewControllers[uuid] != nil {
channel.invokeMethod("onChromeSafariBrowserOpened", arguments: ["uuid": uuid]) SwiftFlutterPlugin.channel!.invokeMethod("onChromeSafariBrowserOpened", arguments: ["uuid": uuid])
} }
} }
func onChromeSafariBrowserLoaded(uuid: String) { func onChromeSafariBrowserLoaded(uuid: String) {
if self.safariViewControllers[uuid] != nil { if self.safariViewControllers[uuid] != nil {
channel.invokeMethod("onChromeSafariBrowserLoaded", arguments: ["uuid": uuid]) SwiftFlutterPlugin.channel!.invokeMethod("onChromeSafariBrowserLoaded", arguments: ["uuid": uuid])
} }
} }
func onChromeSafariBrowserClosed(uuid: String) { func onChromeSafariBrowserClosed(uuid: String) {
channel.invokeMethod("onChromeSafariBrowserClosed", arguments: ["uuid": uuid]) SwiftFlutterPlugin.channel!.invokeMethod("onChromeSafariBrowserClosed", arguments: ["uuid": uuid])
} }
func onCallJsHandler(uuid: String, webView: WKWebView, handlerName: String, args: String) { func onCallJsHandler(uuid: String, webView: WKWebView, handlerName: String, args: String) {
channel.invokeMethod("onCallJsHandler", arguments: ["uuid": uuid, "handlerName": handlerName, "args": args]) SwiftFlutterPlugin.channel!.invokeMethod("onCallJsHandler", arguments: ["uuid": uuid, "handlerName": handlerName, "args": args])
} }
func safariExit(uuid: String) { func safariExit(uuid: String) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment