Manos Chorianopoulos

add WKWebView event handler

......@@ -9,7 +9,7 @@ import Foundation
import UIKit
import WebKit
@objc public class CampaignViewController: UIViewController, WKNavigationDelegate {
@objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
@IBOutlet weak var webview: WKWebView!
public var campaignUrl: String = ""
......@@ -23,6 +23,14 @@ import WebKit
let url = URL(string: campaignUrl)!
webview.load(URLRequest(url: url))
webview.allowsBackForwardNavigationGestures = true
webview.configuration.userContentController.add(self, name: "Cosmote")
}
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
print("=== event callback ===")
print(message.name, message.body)
print("=== event callback ===")
}
}
......