Manos Chorianopoulos

send data in webview via JS

......@@ -14,6 +14,7 @@ import SwiftEventBus
@IBOutlet weak var webview: WKWebView!
public var campaignUrl: String = ""
public var params: String = ""
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -34,6 +35,20 @@ import SwiftEventBus
webview.configuration.userContentController.add(self, name: "Cosmote")
}
// MARK: - WKNavigationDelegate
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let scriptSource = "passParams(\(params));"
webView.evaluateJavaScript(scriptSource, completionHandler: { (object, error) in
print("==== object ====")
print(object)
print("==== error ====")
print(error)
})
}
// MARK: - WKScriptMessageHandler
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if let event = message.body as? String {
......
......@@ -172,6 +172,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
var url = ""
var params = ""
let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true")
if (isCcmsOffer) {
......@@ -187,9 +188,11 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
}
}
url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound)
params = swiftApi().constructCcmsParams(campaigns[indexPath.row], ccmsCampaignFound)
} else {
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
}
......@@ -201,6 +204,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
} else {
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
......@@ -210,6 +214,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
}
print("CampaignUrl url onclick: " + url)
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
} else {
......
......@@ -125,6 +125,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
var url = ""
var params = ""
let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true")
if (isCcmsOffer) {
......@@ -140,9 +141,11 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
}
}
url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound)
params = swiftApi().constructCcmsParams(campaigns[indexPath.row], ccmsCampaignFound)
} else {
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
}
......@@ -154,6 +157,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
} else {
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
......@@ -163,6 +167,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
}
print("CampaignUrl url onclick: " + url)
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
}
}
......