Manos Chorianopoulos

add QuestionnaireEventModel and handle Event

...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
8 import Foundation 8 import Foundation
9 import UIKit 9 import UIKit
10 import WebKit 10 import WebKit
11 +import SwiftEventBus
11 12
12 @objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler { 13 @objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
13 @IBOutlet weak var webview: WKWebView! 14 @IBOutlet weak var webview: WKWebView!
...@@ -31,6 +32,26 @@ import WebKit ...@@ -31,6 +32,26 @@ import WebKit
31 print("=== event callback ===") 32 print("=== event callback ===")
32 print(message.name, message.body) 33 print(message.name, message.body)
33 print("=== event callback ===") 34 print("=== event callback ===")
35 +
36 + if let event = message.body as? String {
37 + let eventArray = event.split(separator: ":")
38 +
39 + if (eventArray[0] == "event") {
40 + if (eventArray[1] == "closeArtwork") {
41 +
42 + } else if (eventArray[1] == "addUserTag") {
43 + let questionnaireEvent = swiftApi.QuestionnaireEventModel()
44 + questionnaireEvent._name = String(eventArray[0])
45 + questionnaireEvent._parameter = String(eventArray[1])
46 + SwiftEventBus.post("questionnaire", sender: questionnaireEvent)
47 +
48 + swiftApi().setUserTag(String(eventArray[2]))
49 +
50 + } else if (eventArray[1] == "couponRetrieved") {
51 +
52 + }
53 + }
54 + }
34 } 55 }
35 56
36 } 57 }
......
...@@ -21,11 +21,11 @@ public class swiftApi { ...@@ -21,11 +21,11 @@ public class swiftApi {
21 } 21 }
22 22
23 public func getUserTag() -> String { 23 public func getUserTag() -> String {
24 - return GlobalVariables.userTag 24 + return UserDefaults.standard.string(forKey: "userTag") ?? ""
25 } 25 }
26 26
27 public func setUserTag(_ newUserTag: String) -> Void { 27 public func setUserTag(_ newUserTag: String) -> Void {
28 - GlobalVariables.userTag = newUserTag 28 + UserDefaults.standard.set(newUserTag, forKey: "userTag")
29 } 29 }
30 30
31 public class DFY { 31 public class DFY {
...@@ -1639,5 +1639,36 @@ public class swiftApi { ...@@ -1639,5 +1639,36 @@ public class swiftApi {
1639 public func getCampaignList() -> Array<CampaignItemModel> { 1639 public func getCampaignList() -> Array<CampaignItemModel> {
1640 return GlobalVariables.campaigns 1640 return GlobalVariables.campaigns
1641 } 1641 }
1642 +
1643 +
1644 + public class QuestionnaireEventModel {
1645 + private var name: String
1646 + private var parameter: String
1647 +
1648 +
1649 + public init() {
1650 + self.name = ""
1651 + self.parameter = ""
1652 +
1653 + }
1654 +
1655 + public var _name: String {
1656 + get { // getter
1657 + return self.name
1658 + }
1659 + set(newValue) { //setter
1660 + self.name = newValue
1661 + }
1662 + }
1663 +
1664 + public var _parameter: String {
1665 + get { // getter
1666 + return self.parameter
1667 + }
1668 + set(newValue) { //setter
1669 + self.parameter = newValue
1670 + }
1671 + }
1672 + }
1642 1673
1643 } 1674 }
......