Manos Chorianopoulos

Add webview Location Permissions

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>0</integer> 10 + <integer>1</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>1</integer> 10 + <integer>0</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -10,15 +10,73 @@ import UIKit ...@@ -10,15 +10,73 @@ import UIKit
10 import WebKit 10 import WebKit
11 import SwiftEventBus 11 import SwiftEventBus
12 12
13 +// Location Permissions
14 +import CoreLocation
15 +
16 +
13 var timer2: DispatchSourceTimer? 17 var timer2: DispatchSourceTimer?
14 18
15 -@objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler { 19 +//@objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
20 +@objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler, CLLocationManagerDelegate, WKUIDelegate, UIScrollViewDelegate {
16 @IBOutlet weak var webview: WKWebView! 21 @IBOutlet weak var webview: WKWebView!
17 22
18 public var campaignUrl: String = "" 23 public var campaignUrl: String = ""
19 public var params: String = "" 24 public var params: String = ""
20 public var showHeader: Bool = false 25 public var showHeader: Bool = false
26 +
27 + // Location Permissions
28 + var webView: WKWebView!
29 + var locationManager: CLLocationManager!
30 + var listenersCount = 0;
31 +
32 + public override func loadView() {
33 + super.loadView();
34 +
35 + locationManager = CLLocationManager()
36 + locationManager.delegate = self
37 + locationManager.desiredAccuracy = kCLLocationAccuracyBest
38 +
39 + let contentController = WKUserContentController()
40 + contentController.add(self, name: "Cosmote")
41 + contentController.add(self, name: "listenerAdded");
42 + contentController.add(self, name: "listenerRemoved");
21 43
44 + let config = WKWebViewConfiguration()
45 + config.userContentController = contentController
46 +
47 + let script = WKUserScript(source: getJavaScripToEvaluate(), injectionTime: .atDocumentEnd, forMainFrameOnly: true)
48 + contentController.addUserScript(script)
49 +
50 + self.webView = WKWebView(frame: self.view.bounds, configuration: config)
51 +
52 + webView?.uiDelegate = self
53 + webView?.navigationDelegate = self
54 + webView?.scrollView.delegate = self
55 + webView?.scrollView.bounces = false
56 + webView?.scrollView.bouncesZoom = false
57 + view.addSubview(webView!)
58 +
59 + }
60 +
61 + public override func viewDidLoad() {
62 + super.viewDidLoad()
63 +
64 + let campaignUrl = campaignUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
65 + print("Webview url: " + (campaignUrl ?? ""))
66 +
67 + if let url = URL(string: campaignUrl ?? "") {
68 + webView.load(URLRequest(url: url))
69 + webView.allowsBackForwardNavigationGestures = true
70 + }
71 +
72 + self.hidesBottomBarWhenPushed = true
73 +
74 + if (showHeader) {
75 + setBackButton()
76 + }
77 +
78 + }
79 +
22 public override func viewWillAppear(_ animated: Bool) { 80 public override func viewWillAppear(_ animated: Bool) {
23 super.viewWillAppear(animated) 81 super.viewWillAppear(animated)
24 if (!showHeader) { 82 if (!showHeader) {
...@@ -61,26 +119,27 @@ var timer2: DispatchSourceTimer? ...@@ -61,26 +119,27 @@ var timer2: DispatchSourceTimer?
61 } 119 }
62 } 120 }
63 121
64 - public override func viewDidLoad() { 122 +// public override func viewDidLoad() {
65 - super.viewDidLoad() 123 +// super.viewDidLoad()
66 - 124 +//
67 - var campaignUrl = campaignUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) 125 +// var campaignUrl = campaignUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
68 - print("Webview url: " + (campaignUrl ?? "")) 126 +// print("Webview url: " + (campaignUrl ?? ""))
69 - 127 +//
70 - self.hidesBottomBarWhenPushed = true 128 +// self.hidesBottomBarWhenPushed = true
71 - 129 +//
72 - if (showHeader) { 130 +// if (showHeader) {
73 - setBackButton() 131 +// setBackButton()
74 - } 132 +// }
75 - 133 +//
76 - webview.navigationDelegate = self 134 +// webview.navigationDelegate = self
77 - if let url = URL(string: campaignUrl ?? "") { 135 +//
78 - webview.load(URLRequest(url: url)) 136 +// if let url = URL(string: campaignUrl ?? "") {
79 - webview.allowsBackForwardNavigationGestures = true 137 +// webview.load(URLRequest(url: url))
80 - } 138 +// webview.allowsBackForwardNavigationGestures = true
81 - 139 +// }
82 - webview.configuration.userContentController.add(self, name: "Cosmote") 140 +//
83 - } 141 +// webview.configuration.userContentController.add(self, name: "Cosmote")
142 +// }
84 143
85 // MARK: - Functions 144 // MARK: - Functions
86 func startTimer() { 145 func startTimer() {
...@@ -121,6 +180,149 @@ var timer2: DispatchSourceTimer? ...@@ -121,6 +180,149 @@ var timer2: DispatchSourceTimer?
121 timer2?.cancel() 180 timer2?.cancel()
122 timer2 = nil 181 timer2 = nil
123 } 182 }
183 +
184 + // Location Permissions
185 + func locationServicesIsEnabled() -> Bool {
186 + return (CLLocationManager.locationServicesEnabled()) ? true : false;
187 + }
188 +
189 + func authorizationStatusNeedRequest(status: CLAuthorizationStatus) -> Bool {
190 + return (status == .notDetermined) ? true : false;
191 + }
192 +
193 + func authorizationStatusIsGranted(status: CLAuthorizationStatus) -> Bool {
194 + return (status == .authorizedAlways || status == .authorizedWhenInUse) ? true : false;
195 + }
196 +
197 + func authorizationStatusIsDenied(status: CLAuthorizationStatus) -> Bool {
198 + return (status == .restricted || status == .denied) ? true : false;
199 + }
200 +
201 + func onLocationServicesIsDisabled() {
202 +// webView.evaluateJavaScript("navigator.geolocation.helper.error(2, 'Location services disabled');");
203 + locationManager.requestWhenInUseAuthorization();
204 + }
205 +
206 + func onAuthorizationStatusNeedRequest() {
207 + locationManager.requestWhenInUseAuthorization();
208 + }
209 +
210 + func onAuthorizationStatusIsGranted() {
211 + locationManager.startUpdatingLocation();
212 + }
213 +
214 + func onAuthorizationStatusIsDenied() {
215 + webView.evaluateJavaScript("navigator.geolocation.helper.error(1, 'App does not have location permission');");
216 + }
217 +
218 + public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
219 + print("=== locationManager didChangeAuthorization: ",status)
220 +
221 + // didChangeAuthorization is also called at app startup, so this condition checks listeners
222 + // count before doing anything otherwise app will start location service without reason
223 + if (listenersCount > 0) {
224 + if (authorizationStatusIsDenied(status: status)) {
225 + onAuthorizationStatusIsDenied();
226 + }
227 + else if (authorizationStatusIsGranted(status: status)) {
228 + onAuthorizationStatusIsGranted();
229 + }
230 + }
231 + }
232 +
233 + public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
234 + if let location = locations.last {
235 + print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude)
236 + print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude)
237 +
238 + webView.evaluateJavaScript("navigator.geolocation.helper.success('\(location.timestamp)', \(location.coordinate.latitude), \(location.coordinate.longitude), \(location.altitude), \(location.horizontalAccuracy), \(location.verticalAccuracy), \(location.course), \(location.speed));");
239 + }
240 + }
241 +
242 + public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
243 + print("=== locationManager didFailWithError: ", error)
244 + webView.evaluateJavaScript("navigator.geolocation.helper.error(2, 'Failed to get position (\(error.localizedDescription))');");
245 + }
246 +
247 + func getJavaScripToEvaluate() -> String {
248 + let javaScripToEvaluate = """
249 + // management for success and error listeners and its calling
250 + navigator.geolocation.helper = {
251 + listeners: {},
252 + noop: function() {},
253 + id: function() {
254 + var min = 1, max = 1000;
255 + return Math.floor(Math.random() * (max - min + 1)) + min;
256 + },
257 + clear: function(isError) {
258 + for (var id in this.listeners) {
259 + if (isError || this.listeners[id].onetime) {
260 + navigator.geolocation.clearWatch(id);
261 + }
262 + }
263 + },
264 + success: function(timestamp, latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed) {
265 + var position = {
266 + timestamp: new Date(timestamp).getTime() || new Date().getTime(), // safari can not parse date format returned by swift e.g. 2019-12-27 15:46:59 +0000 (fallback used because we trust that safari will learn it in future because chrome knows that format)
267 + coords: {
268 + latitude: latitude,
269 + longitude: longitude,
270 + altitude: altitude,
271 + accuracy: accuracy,
272 + altitudeAccuracy: altitudeAccuracy,
273 + heading: (heading > 0) ? heading : null,
274 + speed: (speed > 0) ? speed : null
275 + }
276 + };
277 + for (var id in this.listeners) {
278 + this.listeners[id].success(position);
279 + }
280 + this.clear(false);
281 + },
282 + error: function(code, message) {
283 + var error = {
284 + PERMISSION_DENIED: 1,
285 + POSITION_UNAVAILABLE: 2,
286 + TIMEOUT: 3,
287 + code: code,
288 + message: message
289 + };
290 + for (var id in this.listeners) {
291 + this.listeners[id].error(error);
292 + }
293 + this.clear(true);
294 + }
295 + };
296 +
297 + // @override getCurrentPosition()
298 + navigator.geolocation.getCurrentPosition = function(success, error, options) {
299 + var id = this.helper.id();
300 + this.helper.listeners[id] = { onetime: true, success: success || this.noop, error: error || this.noop };
301 + window.webkit.messageHandlers.listenerAdded.postMessage("");
302 + };
303 +
304 + // @override watchPosition()
305 + navigator.geolocation.watchPosition = function(success, error, options) {
306 + var id = this.helper.id();
307 + this.helper.listeners[id] = { onetime: false, success: success || this.noop, error: error || this.noop };
308 + window.webkit.messageHandlers.listenerAdded.postMessage("");
309 + return id;
310 + };
311 +
312 + // @override clearWatch()
313 + navigator.geolocation.clearWatch = function(id) {
314 + var idExists = (this.helper.listeners[id]) ? true : false;
315 + if (idExists) {
316 + this.helper.listeners[id] = null;
317 + delete this.helper.listeners[id];
318 + window.webkit.messageHandlers.listenerRemoved.postMessage("");
319 + }
320 + };
321 + """;
322 +
323 + return javaScripToEvaluate;
324 + }
325 + // <===
124 326
125 // MARK: - API Calls 327 // MARK: - API Calls
126 func startTrackingSteps() { 328 func startTrackingSteps() {
...@@ -147,239 +349,268 @@ var timer2: DispatchSourceTimer? ...@@ -147,239 +349,268 @@ var timer2: DispatchSourceTimer?
147 self.startTimer() 349 self.startTimer()
148 } 350 }
149 }) 351 })
352 +
150 } 353 }
151 354
152 // MARK: - WKScriptMessageHandler 355 // MARK: - WKScriptMessageHandler
153 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { 356 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
154 357
155 - if let event = message.body as? String { 358 + // Location Permissions
156 - let eventArray = event.split(separator: ":") 359 + if (message.name == "listenerAdded") {
157 - 360 + listenersCount += 1;
158 - if (eventArray[0] == "event") {
159 - if (eventArray[1] == "closeArtwork") {
160 361
161 - self.navigationController?.popViewController(animated: true) 362 + if (!locationServicesIsEnabled()) {
162 - 363 + onLocationServicesIsDisabled();
163 - } else if (eventArray[1] == "addUserTag") { 364 + }
164 - // SwiftEventBus.post("questionnaire", sender: questionnaireEvent) 365 + else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) {
165 - 366 + onAuthorizationStatusIsDenied();
166 - swiftApi().getProfileAsync(getProfileCallback, failureCallback: {errorCode in }) 367 + }
167 - 368 + else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) {
168 - func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void { 369 + onAuthorizationStatusNeedRequest();
169 - if (profileData != nil) { 370 + }
170 - DispatchQueue.main.async { 371 + else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) {
171 - swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 372 + onAuthorizationStatusIsGranted();
172 - 373 + }
173 - func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { 374 + }
174 - if (campaignsData != nil) { 375 + else if (message.name == "listenerRemoved") {
175 - DispatchQueue.main.async { 376 + listenersCount -= 1;
176 - let questionnaireEvent = swiftApi.QuestionnaireEventModel() 377 +
177 - questionnaireEvent._name = String(eventArray[1]) 378 + // no listener left in web view to wait for position
178 - if (eventArray.count > 2) { 379 + if (listenersCount == 0) {
179 - questionnaireEvent._parameter = String(eventArray[2]) 380 + locationManager.stopUpdatingLocation();
180 - swiftApi().setUserTag(String(eventArray[2])) 381 + }
181 - } else { 382 + }
182 - questionnaireEvent._parameter = "" 383 + // <==
183 - swiftApi().setUserTag("") 384 + else if (message.name == "Cosmote") {
385 + if let event = message.body as? String {
386 + let eventArray = event.split(separator: ":")
387 +
388 + if (eventArray[0] == "event") {
389 + if (eventArray[1] == "closeArtwork") {
390 +
391 + self.navigationController?.popViewController(animated: true)
392 +
393 + } else if (eventArray[1] == "addUserTag") {
394 + // SwiftEventBus.post("questionnaire", sender: questionnaireEvent)
395 +
396 + swiftApi().getProfileAsync(getProfileCallback, failureCallback: {errorCode in })
397 +
398 + func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
399 + if (profileData != nil) {
400 + DispatchQueue.main.async {
401 + swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
402 +
403 + func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
404 + if (campaignsData != nil) {
405 + DispatchQueue.main.async {
406 + let questionnaireEvent = swiftApi.QuestionnaireEventModel()
407 + questionnaireEvent._name = String(eventArray[1])
408 + if (eventArray.count > 2) {
409 + questionnaireEvent._parameter = String(eventArray[2])
410 + swiftApi().setUserTag(String(eventArray[2]))
411 + } else {
412 + questionnaireEvent._parameter = ""
413 + swiftApi().setUserTag("")
414 + }
415 + SwiftEventBus.post("questionnaire", sender: questionnaireEvent)
416 + SwiftEventBus.post("campaigns_retrieved")
184 } 417 }
185 - SwiftEventBus.post("questionnaire", sender: questionnaireEvent) 418 + } else {
186 - SwiftEventBus.post("campaigns_retrieved")
187 } 419 }
188 - } else {
189 } 420 }
421 +
190 } 422 }
423 + } else {
424 + }
425 + }
426 +
427 +
428 + } else if (eventArray[1] == "couponRetrieved") {
429 + let couponEvent = swiftApi.CouponEventModel()
430 + SwiftEventBus.post("coupon_retrieved", sender: couponEvent)
431 +
432 + swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
433 + swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
434 +
435 + func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
436 + if (couponsData != nil) {
191 437
438 + DispatchQueue.main.async {
439 + SwiftEventBus.post("coupons_fetched")
440 + }
441 + } else {
192 } 442 }
193 - } else {
194 } 443 }
444 +
445 + func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
446 + if (campaignsData != nil) {
447 + DispatchQueue.main.async {
448 + SwiftEventBus.post("campaigns_retrieved")
449 + }
450 + } else {
451 + }
452 + }
453 +
454 + } else if (eventArray[1] == "ccmsRetrieved") {
455 + let ccmsEnabled = swiftApi.WarplyCCMSEnabledModel()
456 + ccmsEnabled._isActivated = true
457 + SwiftEventBus.post("ccms_enabled", sender: ccmsEnabled)
458 +
459 + } else if (eventArray[1] == "couponShared") {
460 +
195 } 461 }
196 - 462 + else if (eventArray[1] == "steps" && eventArray[2] == "widgetDisabled") {
197 - 463 + let pacingWidget = swiftApi.WarplyPacingCardEventModel()
198 - } else if (eventArray[1] == "couponRetrieved") { 464 + pacingWidget._isVisible = false
199 - let couponEvent = swiftApi.CouponEventModel() 465 + SwiftEventBus.post("pacing_widget", sender: pacingWidget)
200 - SwiftEventBus.post("coupon_retrieved", sender: couponEvent) 466 +
201 - 467 + } else if (eventArray[1] == "steps" && eventArray[2] == "widgetEnabled") {
202 - swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in }) 468 + let pacingWidget = swiftApi.WarplyPacingCardEventModel()
203 - swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 469 + pacingWidget._isVisible = true
204 - 470 + SwiftEventBus.post("pacing_widget", sender: pacingWidget)
205 - func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void { 471 +
206 - if (couponsData != nil) { 472 + }
473 + else if (eventArray[1] == "steps" && eventArray[2] == "shortcutEnabled") {
474 + let pacingEvent = swiftApi.WarplyPacingEventModel()
475 + pacingEvent._isVisible = true
476 + SwiftEventBus.post("pacing", sender: pacingEvent)
477 +
478 + if (swiftApi().getTrackingStepsEnabled() == false) {
479 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
480 + firebaseEvent._eventName = "loyalty_steps_activation"
481 + firebaseEvent._parameters = nil
482 + SwiftEventBus.post("firebase", sender: firebaseEvent)
207 483
208 - DispatchQueue.main.async { 484 + self.startTrackingSteps()
209 - SwiftEventBus.post("coupons_fetched") 485 + }
210 - } 486 +
487 + } else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") {
488 + let pacingEvent = swiftApi.WarplyPacingEventModel()
489 + pacingEvent._isVisible = false
490 + SwiftEventBus.post("pacing", sender: pacingEvent)
491 + swiftApi().stopTrackingSteps()
492 +
493 + } else if (eventArray[1] == "request" || eventArray[1] == "response") {
494 + print("**************** WARPLY Webview Log START *****************")
495 + print(event)
496 + print("**************** WARPLY Webview Log END *****************")
497 +
498 + } else if (eventArray[1] == "loyalty_questionnaire_selected") {
499 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
500 + firebaseEvent._eventName = "loyalty_questionnaire_selected"
501 + firebaseEvent.setParameter = ("completed", "true")
502 + SwiftEventBus.post("firebase", sender: firebaseEvent)
503 +
504 + } else if (eventArray[1] == "loyalty_questionnaire_answer_again") {
505 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
506 + firebaseEvent._eventName = "loyalty_questionnaire_answer_again"
507 + firebaseEvent._parameters = nil
508 + SwiftEventBus.post("firebase", sender: firebaseEvent)
509 +
510 + } else if (eventArray[1] == "loyalty_questionnaire_answers_deleted") {
511 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
512 + firebaseEvent._eventName = "loyalty_questionnaire_answers_deleted"
513 + firebaseEvent._parameters = nil
514 + SwiftEventBus.post("firebase", sender: firebaseEvent)
515 +
516 + } else if (eventArray[1] == "loyalty_questionnaire_later") {
517 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
518 + firebaseEvent._eventName = "loyalty_questionnaire_later"
519 + firebaseEvent.setParameter = ("completed", "false")
520 + SwiftEventBus.post("firebase", sender: firebaseEvent)
521 +
522 + } else if (eventArray[1] == "loyalty_sdk_offer_selected") {
523 + var name: String = ""
524 + if (eventArray.count > 2) {
525 + name = String(eventArray[2])
211 } else { 526 } else {
527 + name = ""
212 } 528 }
213 - } 529 +
214 - 530 + var type: String = ""
215 - func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { 531 + if (eventArray.count > 3) {
216 - if (campaignsData != nil) { 532 + type = String(eventArray[3])
217 - DispatchQueue.main.async {
218 - SwiftEventBus.post("campaigns_retrieved")
219 - }
220 } else { 533 } else {
534 + type = ""
221 } 535 }
222 - } 536 +
223 -
224 - } else if (eventArray[1] == "ccmsRetrieved") {
225 - let ccmsEnabled = swiftApi.WarplyCCMSEnabledModel()
226 - ccmsEnabled._isActivated = true
227 - SwiftEventBus.post("ccms_enabled", sender: ccmsEnabled)
228 -
229 - } else if (eventArray[1] == "couponShared") {
230 -
231 - }
232 - else if (eventArray[1] == "steps" && eventArray[2] == "widgetDisabled") {
233 - let pacingWidget = swiftApi.WarplyPacingCardEventModel()
234 - pacingWidget._isVisible = false
235 - SwiftEventBus.post("pacing_widget", sender: pacingWidget)
236 -
237 - } else if (eventArray[1] == "steps" && eventArray[2] == "widgetEnabled") {
238 - let pacingWidget = swiftApi.WarplyPacingCardEventModel()
239 - pacingWidget._isVisible = true
240 - SwiftEventBus.post("pacing_widget", sender: pacingWidget)
241 -
242 - }
243 - else if (eventArray[1] == "steps" && eventArray[2] == "shortcutEnabled") {
244 - let pacingEvent = swiftApi.WarplyPacingEventModel()
245 - pacingEvent._isVisible = true
246 - SwiftEventBus.post("pacing", sender: pacingEvent)
247 -
248 - if (swiftApi().getTrackingStepsEnabled() == false) {
249 let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() 537 let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
250 - firebaseEvent._eventName = "loyalty_steps_activation" 538 + firebaseEvent._eventName = "loyalty_sdk_offer_selected"
251 - firebaseEvent._parameters = nil 539 + firebaseEvent.setParameter = ("name", name)
540 + firebaseEvent.setParameter = ("type", type)
252 SwiftEventBus.post("firebase", sender: firebaseEvent) 541 SwiftEventBus.post("firebase", sender: firebaseEvent)
253 - 542 +
254 - self.startTrackingSteps() 543 + } else if (eventArray[1] == "loyalty_offer_activated") {
255 - } 544 + var name: String = ""
256 - 545 + if (eventArray.count > 2) {
257 - } else if (eventArray[1] == "steps" && eventArray[2] == "shortcutDisabled") { 546 + name = String(eventArray[2])
258 - let pacingEvent = swiftApi.WarplyPacingEventModel() 547 + } else {
259 - pacingEvent._isVisible = false 548 + name = ""
260 - SwiftEventBus.post("pacing", sender: pacingEvent) 549 + }
261 - swiftApi().stopTrackingSteps() 550 +
262 - 551 + var type: String = ""
263 - } else if (eventArray[1] == "request" || eventArray[1] == "response") { 552 + if (eventArray.count > 3) {
264 - print("**************** WARPLY Webview Log START *****************") 553 + type = String(eventArray[3])
265 - print(event) 554 + } else {
266 - print("**************** WARPLY Webview Log END *****************") 555 + type = ""
267 - 556 + }
268 - } else if (eventArray[1] == "loyalty_questionnaire_selected") { 557 +
269 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() 558 + var successful: String = ""
270 - firebaseEvent._eventName = "loyalty_questionnaire_selected" 559 + if (eventArray.count > 4) {
271 - firebaseEvent.setParameter = ("completed", "true") 560 + successful = String(eventArray[4])
272 - SwiftEventBus.post("firebase", sender: firebaseEvent) 561 + } else {
273 - 562 + successful = ""
274 - } else if (eventArray[1] == "loyalty_questionnaire_answer_again") { 563 + }
275 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() 564 +
276 - firebaseEvent._eventName = "loyalty_questionnaire_answer_again" 565 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
277 - firebaseEvent._parameters = nil 566 + firebaseEvent._eventName = "loyalty_offer_activated"
278 - SwiftEventBus.post("firebase", sender: firebaseEvent) 567 + firebaseEvent.setParameter = ("name", name)
279 - 568 + firebaseEvent.setParameter = ("type", type)
280 - } else if (eventArray[1] == "loyalty_questionnaire_answers_deleted") { 569 + firebaseEvent.setParameter = ("successful", successful)
281 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() 570 + SwiftEventBus.post("firebase", sender: firebaseEvent)
282 - firebaseEvent._eventName = "loyalty_questionnaire_answers_deleted" 571 +
283 - firebaseEvent._parameters = nil 572 + } else if (eventArray[1] == "time_spent_on_loyalty_sdk") {
284 - SwiftEventBus.post("firebase", sender: firebaseEvent) 573 + var name: String = ""
285 - 574 + if (eventArray.count > 2) {
286 - } else if (eventArray[1] == "loyalty_questionnaire_later") { 575 + name = String(eventArray[2])
287 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() 576 + } else {
288 - firebaseEvent._eventName = "loyalty_questionnaire_later" 577 + name = ""
289 - firebaseEvent.setParameter = ("completed", "false") 578 + }
290 - SwiftEventBus.post("firebase", sender: firebaseEvent) 579 +
291 - 580 + var seconds: String = ""
292 - } else if (eventArray[1] == "loyalty_sdk_offer_selected") { 581 + if (eventArray.count > 3) {
293 - var name: String = "" 582 + seconds = String(eventArray[3])
294 - if (eventArray.count > 2) { 583 + } else {
295 - name = String(eventArray[2]) 584 + seconds = ""
296 - } else { 585 + }
297 - name = "" 586 +
298 - } 587 + let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
299 - 588 + firebaseEvent._eventName = "time_spent_on_loyalty_sdk"
300 - var type: String = "" 589 + firebaseEvent.setParameter = ("name", name)
301 - if (eventArray.count > 3) { 590 + firebaseEvent.setParameter = ("seconds", seconds)
302 - type = String(eventArray[3]) 591 + SwiftEventBus.post("firebase", sender: firebaseEvent)
303 - } else { 592 +
304 - type = "" 593 + } else if (eventArray[1] == "refreshToken") {
305 - } 594 + var access_token: String = ""
306 - 595 + if (eventArray.count > 2) {
307 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel() 596 + access_token = String(eventArray[2])
308 - firebaseEvent._eventName = "loyalty_sdk_offer_selected" 597 + } else {
309 - firebaseEvent.setParameter = ("name", name) 598 + access_token = ""
310 - firebaseEvent.setParameter = ("type", type) 599 + }
311 - SwiftEventBus.post("firebase", sender: firebaseEvent) 600 +
312 - 601 + var refresh_token: String = ""
313 - } else if (eventArray[1] == "loyalty_offer_activated") { 602 + if (eventArray.count > 3) {
314 - var name: String = "" 603 + refresh_token = String(eventArray[3])
315 - if (eventArray.count > 2) { 604 + } else {
316 - name = String(eventArray[2]) 605 + refresh_token = ""
317 - } else { 606 + }
318 - name = "" 607 +
319 - } 608 + if (access_token != "" && refresh_token != "") {
320 - 609 + swiftApi().updateRefreshToken(access_token: access_token, refresh_token: refresh_token)
321 - var type: String = "" 610 + }
322 - if (eventArray.count > 3) {
323 - type = String(eventArray[3])
324 - } else {
325 - type = ""
326 - }
327 -
328 - var successful: String = ""
329 - if (eventArray.count > 4) {
330 - successful = String(eventArray[4])
331 - } else {
332 - successful = ""
333 - }
334 -
335 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
336 - firebaseEvent._eventName = "loyalty_offer_activated"
337 - firebaseEvent.setParameter = ("name", name)
338 - firebaseEvent.setParameter = ("type", type)
339 - firebaseEvent.setParameter = ("successful", successful)
340 - SwiftEventBus.post("firebase", sender: firebaseEvent)
341 -
342 - } else if (eventArray[1] == "time_spent_on_loyalty_sdk") {
343 - var name: String = ""
344 - if (eventArray.count > 2) {
345 - name = String(eventArray[2])
346 - } else {
347 - name = ""
348 - }
349 -
350 - var seconds: String = ""
351 - if (eventArray.count > 3) {
352 - seconds = String(eventArray[3])
353 - } else {
354 - seconds = ""
355 - }
356 -
357 - let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
358 - firebaseEvent._eventName = "time_spent_on_loyalty_sdk"
359 - firebaseEvent.setParameter = ("name", name)
360 - firebaseEvent.setParameter = ("seconds", seconds)
361 - SwiftEventBus.post("firebase", sender: firebaseEvent)
362 -
363 - } else if (eventArray[1] == "refreshToken") {
364 - var access_token: String = ""
365 - if (eventArray.count > 2) {
366 - access_token = String(eventArray[2])
367 - } else {
368 - access_token = ""
369 - }
370 -
371 - var refresh_token: String = ""
372 - if (eventArray.count > 3) {
373 - refresh_token = String(eventArray[3])
374 - } else {
375 - refresh_token = ""
376 } 611 }
377 612
378 - if (access_token != "" && refresh_token != "") {
379 - swiftApi().updateRefreshToken(access_token: access_token, refresh_token: refresh_token)
380 - }
381 } 613 }
382 -
383 } 614 }
384 } 615 }
385 } 616 }
......
...@@ -403,6 +403,11 @@ ...@@ -403,6 +403,11 @@
403 <constraint firstItem="bHn-Kz-pbS" firstAttribute="leading" secondItem="iPT-gj-hEL" secondAttribute="leading" id="UTz-nY-JvS"/> 403 <constraint firstItem="bHn-Kz-pbS" firstAttribute="leading" secondItem="iPT-gj-hEL" secondAttribute="leading" id="UTz-nY-JvS"/>
404 <constraint firstItem="bHn-Kz-pbS" firstAttribute="top" secondItem="iPT-gj-hEL" secondAttribute="top" id="WKD-3C-3kF"/> 404 <constraint firstItem="bHn-Kz-pbS" firstAttribute="top" secondItem="iPT-gj-hEL" secondAttribute="top" id="WKD-3C-3kF"/>
405 </constraints> 405 </constraints>
406 + <variation key="default">
407 + <mask key="subviews">
408 + <exclude reference="bHn-Kz-pbS"/>
409 + </mask>
410 + </variation>
406 </view> 411 </view>
407 </subviews> 412 </subviews>
408 <viewLayoutGuide key="safeArea" id="xUc-yV-Y8f"/> 413 <viewLayoutGuide key="safeArea" id="xUc-yV-Y8f"/>
......