Manos Chorianopoulos

add QuestionnaireEventModel and handle Event

......@@ -8,6 +8,7 @@
import Foundation
import UIKit
import WebKit
import SwiftEventBus
@objc public class CampaignViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
@IBOutlet weak var webview: WKWebView!
......@@ -31,6 +32,26 @@ import WebKit
print("=== event callback ===")
print(message.name, message.body)
print("=== event callback ===")
if let event = message.body as? String {
let eventArray = event.split(separator: ":")
if (eventArray[0] == "event") {
if (eventArray[1] == "closeArtwork") {
} else if (eventArray[1] == "addUserTag") {
let questionnaireEvent = swiftApi.QuestionnaireEventModel()
questionnaireEvent._name = String(eventArray[0])
questionnaireEvent._parameter = String(eventArray[1])
SwiftEventBus.post("questionnaire", sender: questionnaireEvent)
swiftApi().setUserTag(String(eventArray[2]))
} else if (eventArray[1] == "couponRetrieved") {
}
}
}
}
}
......
......@@ -21,11 +21,11 @@ public class swiftApi {
}
public func getUserTag() -> String {
return GlobalVariables.userTag
return UserDefaults.standard.string(forKey: "userTag") ?? ""
}
public func setUserTag(_ newUserTag: String) -> Void {
GlobalVariables.userTag = newUserTag
UserDefaults.standard.set(newUserTag, forKey: "userTag")
}
public class DFY {
......@@ -1640,4 +1640,35 @@ public class swiftApi {
return GlobalVariables.campaigns
}
public class QuestionnaireEventModel {
private var name: String
private var parameter: String
public init() {
self.name = ""
self.parameter = ""
}
public var _name: String {
get { // getter
return self.name
}
set(newValue) { //setter
self.name = newValue
}
}
public var _parameter: String {
get { // getter
return self.parameter
}
set(newValue) { //setter
self.parameter = newValue
}
}
}
}
......