Manos Chorianopoulos

send data in webview via JS

...@@ -14,6 +14,7 @@ import SwiftEventBus ...@@ -14,6 +14,7 @@ import SwiftEventBus
14 @IBOutlet weak var webview: WKWebView! 14 @IBOutlet weak var webview: WKWebView!
15 15
16 public var campaignUrl: String = "" 16 public var campaignUrl: String = ""
17 + public var params: String = ""
17 18
18 public override func viewDidLoad() { 19 public override func viewDidLoad() {
19 super.viewDidLoad() 20 super.viewDidLoad()
...@@ -34,6 +35,20 @@ import SwiftEventBus ...@@ -34,6 +35,20 @@ import SwiftEventBus
34 webview.configuration.userContentController.add(self, name: "Cosmote") 35 webview.configuration.userContentController.add(self, name: "Cosmote")
35 } 36 }
36 37
38 + // MARK: - WKNavigationDelegate
39 + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
40 +
41 + let scriptSource = "passParams(\(params));"
42 +
43 + webView.evaluateJavaScript(scriptSource, completionHandler: { (object, error) in
44 + print("==== object ====")
45 + print(object)
46 + print("==== error ====")
47 + print(error)
48 + })
49 + }
50 +
51 + // MARK: - WKScriptMessageHandler
37 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { 52 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
38 53
39 if let event = message.body as? String { 54 if let event = message.body as? String {
......
...@@ -172,6 +172,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -172,6 +172,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
172 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self)) 172 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
173 let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController 173 let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
174 var url = "" 174 var url = ""
175 + var params = ""
175 let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true") 176 let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true")
176 177
177 if (isCcmsOffer) { 178 if (isCcmsOffer) {
...@@ -187,9 +188,11 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -187,9 +188,11 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
187 } 188 }
188 } 189 }
189 url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound) 190 url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound)
191 + params = swiftApi().constructCcmsParams(campaigns[indexPath.row], ccmsCampaignFound)
190 192
191 } else { 193 } else {
192 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row]) 194 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
195 + params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
193 196
194 } 197 }
195 198
...@@ -201,6 +204,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -201,6 +204,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
201 204
202 } else { 205 } else {
203 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row]) 206 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
207 + params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
204 208
205 let encoder = JSONEncoder() 209 let encoder = JSONEncoder()
206 encoder.outputFormatting = .prettyPrinted 210 encoder.outputFormatting = .prettyPrinted
...@@ -210,6 +214,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -210,6 +214,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
210 } 214 }
211 print("CampaignUrl url onclick: " + url) 215 print("CampaignUrl url onclick: " + url)
212 vc.campaignUrl = url 216 vc.campaignUrl = url
217 + vc.params = params
213 self.navigationController?.pushViewController(vc, animated: true) 218 self.navigationController?.pushViewController(vc, animated: true)
214 219
215 } else { 220 } else {
......
...@@ -125,6 +125,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -125,6 +125,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
125 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self)) 125 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
126 let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController 126 let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
127 var url = "" 127 var url = ""
128 + var params = ""
128 let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true") 129 let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true")
129 130
130 if (isCcmsOffer) { 131 if (isCcmsOffer) {
...@@ -140,9 +141,11 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -140,9 +141,11 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
140 } 141 }
141 } 142 }
142 url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound) 143 url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound)
144 + params = swiftApi().constructCcmsParams(campaigns[indexPath.row], ccmsCampaignFound)
143 145
144 } else { 146 } else {
145 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row]) 147 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
148 + params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
146 149
147 } 150 }
148 151
...@@ -154,6 +157,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -154,6 +157,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
154 157
155 } else { 158 } else {
156 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row]) 159 url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
160 + params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
157 161
158 let encoder = JSONEncoder() 162 let encoder = JSONEncoder()
159 encoder.outputFormatting = .prettyPrinted 163 encoder.outputFormatting = .prettyPrinted
...@@ -163,6 +167,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -163,6 +167,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
163 } 167 }
164 print("CampaignUrl url onclick: " + url) 168 print("CampaignUrl url onclick: " + url)
165 vc.campaignUrl = url 169 vc.campaignUrl = url
170 + vc.params = params
166 self.navigationController?.pushViewController(vc, animated: true) 171 self.navigationController?.pushViewController(vc, animated: true)
167 } 172 }
168 } 173 }
......