Manos Chorianopoulos

add WKWebView event handler

...@@ -9,7 +9,7 @@ import Foundation ...@@ -9,7 +9,7 @@ import Foundation
9 import UIKit 9 import UIKit
10 import WebKit 10 import WebKit
11 11
12 -@objc public class CampaignViewController: UIViewController, WKNavigationDelegate { 12 +@objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
13 @IBOutlet weak var webview: WKWebView! 13 @IBOutlet weak var webview: WKWebView!
14 14
15 public var campaignUrl: String = "" 15 public var campaignUrl: String = ""
...@@ -23,6 +23,14 @@ import WebKit ...@@ -23,6 +23,14 @@ import WebKit
23 let url = URL(string: campaignUrl)! 23 let url = URL(string: campaignUrl)!
24 webview.load(URLRequest(url: url)) 24 webview.load(URLRequest(url: url))
25 webview.allowsBackForwardNavigationGestures = true 25 webview.allowsBackForwardNavigationGestures = true
26 +
27 + webview.configuration.userContentController.add(self, name: "Cosmote")
28 + }
29 +
30 + func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
31 + print("=== event callback ===")
32 + print(message.name, message.body)
33 + print("=== event callback ===")
26 } 34 }
27 35
28 } 36 }
......