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)
}
}
......
......@@ -2012,22 +2012,20 @@ public class swiftApi {
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let finalUrl = (campaign.index_url ?? "")
+ "?web_id=" + (campaignInfo?["web_id"] as! String)
+ "&app_uuid=" + (campaignInfo?["app_uuid"] as! String)
+ "&api_key=" + (campaignInfo?["api_key"] as! String)
+ "&session_uuid=" + (campaign.session_uuid ?? "")
+ "&access_token=" + (campaignInfo?["access_token"] as! String)
+ "&refresh_token=" + (campaignInfo?["refresh_token"] as! String)
+ "&client_id=" + (campaignInfo?["client_id"] as! String)
+ "&client_secret=" + (campaignInfo?["client_secret"] as! String);
// + "?web_id=" + (campaignInfo?["web_id"] as! String)
// + "&app_uuid=" + (campaignInfo?["app_uuid"] as! String)
// + "&api_key=" + (campaignInfo?["api_key"] as! String)
// + "&session_uuid=" + (campaign.session_uuid ?? "")
// + "&access_token=" + (campaignInfo?["access_token"] as! String)
// + "&refresh_token=" + (campaignInfo?["refresh_token"] as! String)
// + "&client_id=" + (campaignInfo?["client_id"] as! String)
// + "&client_secret=" + (campaignInfo?["client_secret"] as! String);
print("constructCampaignUrl url: " + finalUrl)
return finalUrl
}
public func constructCcmsUrl(_ campaign: LoyaltyContextualOfferModel) -> String {
// TODO: DELETE
print("======== constructCcmsUrl 1 arg ========")
for item in GlobalVariables.campaigns {
if (item.session_uuid == campaign._loyaltyCampaignId) {
print("CCMS_PRESSED" + " " + campaign._id + " " + campaign._offerName)
......@@ -2048,36 +2046,36 @@ public class swiftApi {
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let finalUrl = (item.index_url ?? "")
+ "?web_id=" + (campaignInfo?["web_id"] as? String ?? "")
+ "&app_uuid=" + (campaignInfo?["app_uuid"] as? String ?? "")
+ "&api_key=" + (campaignInfo?["api_key"] as? String ?? "")
+ "&session_uuid=" + (item.session_uuid ?? "")
+ "&access_token=" + (campaignInfo?["access_token"] as? String ?? "")
+ "&refresh_token=" + (campaignInfo?["refresh_token"] as? String ?? "")
+ "&client_id=" + (campaignInfo?["client_id"] as? String ?? "")
+ "&client_secret=" + (campaignInfo?["client_secret"] as? String ?? "")
+ "&Session_ID=" + (campaign._sessionId)
+ "&businessService=" + (campaign._businessService)
+ "&offerName=" + (campaign._offerName)
+ "&productType=" + (campaign._productType)
+ "&provDuration=" + (campaign._provDuration)
+ "&noOfRecurrance=" + (campaign._noOfRecurrance)
+ "&price=" + (campaign._price)
+ "&discount=" + (campaign._discount)
+ "&voiceCategory=" + (campaign._voiceCategory)
+ "&dataCategory=" + (campaign._dataCategory)
+ "&minsValue=" + (campaign._minsValue)
+ "&dataValue=" + (campaign._dataValue)
+ "&provStepValueMins=" + (campaign._provStepValueMins)
+ "&UACIOfferTrackingCode=" + (campaign._uaciOfferTrackingCode)
+ "&OFFERCODE1=" + (campaign._offerCode1)
+ "&SCORE=" + (campaign._score)
+ "&WAVE=" + (campaign._wave)
+ "&VALIDITY=" + (campaign._validity)
+ "&TREATMENT_CODE=" + (campaign._treatmentCode)
+ "&OfferAudienceLevel=" + (campaign._offerAudienceLevel)
+ "&ASSETS=" + (assetsString)
+ "&ZONE=" + (campaign._zone);
// + "?web_id=" + (campaignInfo?["web_id"] as? String ?? "")
// + "&app_uuid=" + (campaignInfo?["app_uuid"] as? String ?? "")
// + "&api_key=" + (campaignInfo?["api_key"] as? String ?? "")
// + "&session_uuid=" + (item.session_uuid ?? "")
// + "&access_token=" + (campaignInfo?["access_token"] as? String ?? "")
// + "&refresh_token=" + (campaignInfo?["refresh_token"] as? String ?? "")
// + "&client_id=" + (campaignInfo?["client_id"] as? String ?? "")
// + "&client_secret=" + (campaignInfo?["client_secret"] as? String ?? "")
// + "&Session_ID=" + (campaign._sessionId)
// + "&businessService=" + (campaign._businessService)
// + "&offerName=" + (campaign._offerName)
// + "&productType=" + (campaign._productType)
// + "&provDuration=" + (campaign._provDuration)
// + "&noOfRecurrance=" + (campaign._noOfRecurrance)
// + "&price=" + (campaign._price)
// + "&discount=" + (campaign._discount)
// + "&voiceCategory=" + (campaign._voiceCategory)
// + "&dataCategory=" + (campaign._dataCategory)
// + "&minsValue=" + (campaign._minsValue)
// + "&dataValue=" + (campaign._dataValue)
// + "&provStepValueMins=" + (campaign._provStepValueMins)
// + "&UACIOfferTrackingCode=" + (campaign._uaciOfferTrackingCode)
// + "&OFFERCODE1=" + (campaign._offerCode1)
// + "&SCORE=" + (campaign._score)
// + "&WAVE=" + (campaign._wave)
// + "&VALIDITY=" + (campaign._validity)
// + "&TREATMENT_CODE=" + (campaign._treatmentCode)
// + "&OfferAudienceLevel=" + (campaign._offerAudienceLevel)
// + "&ASSETS=" + (assetsString)
// + "&ZONE=" + (campaign._zone);
// + "&OfferAudienceLevel=" + (campaign._eligibleAssets != nil && campaign._eligibleAssets.count > 0 ? "MSISDN" : "GUID")
......@@ -2087,14 +2085,10 @@ public class swiftApi {
}
}
print("constructCcmsUrl url: " + "")
// TODO: DELETE
print("======== constructCcmsUrl 1 arg: ccms not matched ========")
return ""
}
public func constructCcmsUrl(_ campaign: CampaignItemModel, _ ccmsCampaign: LoyaltyContextualOfferModel) -> String {
// TODO: DELETE
print("======== constructCcmsUrl 2 args ========")
print("CCMS_PRESSED" + " " + ccmsCampaign._id + " " + ccmsCampaign._offerName)
var assetsString = ""
......@@ -2111,42 +2105,204 @@ public class swiftApi {
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let finalUrl = (campaign.index_url ?? "")
+ "?web_id=" + (campaignInfo?["web_id"] as? String ?? "")
+ "&app_uuid=" + (campaignInfo?["app_uuid"] as? String ?? "")
+ "&api_key=" + (campaignInfo?["api_key"] as? String ?? "")
+ "&session_uuid=" + (campaign.session_uuid ?? "")
+ "&access_token=" + (campaignInfo?["access_token"] as? String ?? "")
+ "&refresh_token=" + (campaignInfo?["refresh_token"] as? String ?? "")
+ "&client_id=" + (campaignInfo?["client_id"] as? String ?? "")
+ "&client_secret=" + (campaignInfo?["client_secret"] as? String ?? "")
+ "&Session_ID=" + (ccmsCampaign._sessionId)
+ "&businessService=" + (ccmsCampaign._businessService)
+ "&offerName=" + (ccmsCampaign._offerName)
+ "&productType=" + (ccmsCampaign._productType)
+ "&provDuration=" + (ccmsCampaign._provDuration)
+ "&noOfRecurrance=" + (ccmsCampaign._noOfRecurrance)
+ "&price=" + (ccmsCampaign._price)
+ "&discount=" + (ccmsCampaign._discount)
+ "&voiceCategory=" + (ccmsCampaign._voiceCategory)
+ "&dataCategory=" + (ccmsCampaign._dataCategory)
+ "&minsValue=" + (ccmsCampaign._minsValue)
+ "&dataValue=" + (ccmsCampaign._dataValue)
+ "&provStepValueMins=" + (ccmsCampaign._provStepValueMins)
+ "&UACIOfferTrackingCode=" + (ccmsCampaign._uaciOfferTrackingCode)
+ "&OFFERCODE1=" + (ccmsCampaign._offerCode1)
+ "&SCORE=" + (ccmsCampaign._score)
+ "&WAVE=" + (ccmsCampaign._wave)
+ "&VALIDITY=" + (ccmsCampaign._validity)
+ "&TREATMENT_CODE=" + (ccmsCampaign._treatmentCode)
+ "&OfferAudienceLevel=" + (ccmsCampaign._offerAudienceLevel)
+ "&ASSETS=" + (assetsString)
+ "&ZONE=" + (ccmsCampaign._zone);
// + "?web_id=" + (campaignInfo?["web_id"] as? String ?? "")
// + "&app_uuid=" + (campaignInfo?["app_uuid"] as? String ?? "")
// + "&api_key=" + (campaignInfo?["api_key"] as? String ?? "")
// + "&session_uuid=" + (campaign.session_uuid ?? "")
// + "&access_token=" + (campaignInfo?["access_token"] as? String ?? "")
// + "&refresh_token=" + (campaignInfo?["refresh_token"] as? String ?? "")
// + "&client_id=" + (campaignInfo?["client_id"] as? String ?? "")
// + "&client_secret=" + (campaignInfo?["client_secret"] as? String ?? "")
// + "&Session_ID=" + (ccmsCampaign._sessionId)
// + "&businessService=" + (ccmsCampaign._businessService)
// + "&offerName=" + (ccmsCampaign._offerName)
// + "&productType=" + (ccmsCampaign._productType)
// + "&provDuration=" + (ccmsCampaign._provDuration)
// + "&noOfRecurrance=" + (ccmsCampaign._noOfRecurrance)
// + "&price=" + (ccmsCampaign._price)
// + "&discount=" + (ccmsCampaign._discount)
// + "&voiceCategory=" + (ccmsCampaign._voiceCategory)
// + "&dataCategory=" + (ccmsCampaign._dataCategory)
// + "&minsValue=" + (ccmsCampaign._minsValue)
// + "&dataValue=" + (ccmsCampaign._dataValue)
// + "&provStepValueMins=" + (ccmsCampaign._provStepValueMins)
// + "&UACIOfferTrackingCode=" + (ccmsCampaign._uaciOfferTrackingCode)
// + "&OFFERCODE1=" + (ccmsCampaign._offerCode1)
// + "&SCORE=" + (ccmsCampaign._score)
// + "&WAVE=" + (ccmsCampaign._wave)
// + "&VALIDITY=" + (ccmsCampaign._validity)
// + "&TREATMENT_CODE=" + (ccmsCampaign._treatmentCode)
// + "&OfferAudienceLevel=" + (ccmsCampaign._offerAudienceLevel)
// + "&ASSETS=" + (assetsString)
// + "&ZONE=" + (ccmsCampaign._zone);
// + "&OfferAudienceLevel=" + (ccmsCampaign._eligibleAssets != nil && ccmsCampaign._eligibleAssets.count > 0 ? "MSISDN" : "GUID")
print("constructCcmsUrl url: " + finalUrl)
return finalUrl
}
public func constructCampaignParams(_ campaign: CampaignItemModel) -> String {
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let jsonObject: [String: String] = [
"web_id": (campaignInfo?["web_id"] as! String),
"app_uuid": (campaignInfo?["app_uuid"] as! String),
"api_key": (campaignInfo?["api_key"] as! String),
"session_uuid": (campaign.session_uuid ?? ""),
"access_token": (campaignInfo?["access_token"] as! String),
"refresh_token": (campaignInfo?["refresh_token"] as! String),
"client_id": (campaignInfo?["client_id"] as! String),
"client_secret": (campaignInfo?["client_secret"] as! String)
]
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(jsonObject)
let stringData = String(data: data, encoding: .utf8) ?? ""
print("constructCampaignParams: " + stringData)
return stringData
// do {
// let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
// let stringData = String(data: data, encoding: String.Encoding.utf8) ?? ""
// print("constructCampaignParams: " + stringData)
// return stringData
// } catch {
// print("constructCampaignParams: ")
// return ""
// }
}
public func constructCcmsParams(_ campaign: LoyaltyContextualOfferModel) -> String {
for item in GlobalVariables.campaigns {
if (item.session_uuid == campaign._loyaltyCampaignId) {
var assetsString = ""
if (campaign._eligibleAssets != nil && campaign._eligibleAssets.count > 0) {
for (index, item) in campaign._eligibleAssets.enumerated() {
if (index == (campaign._eligibleAssets.endIndex - 1)) {
assetsString += String(item)
} else {
assetsString += String(item) + ","
}
}
}
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let jsonObject: [String: String] = [
"web_id": (campaignInfo?["web_id"] as? String ?? ""),
"app_uuid": (campaignInfo?["app_uuid"] as? String ?? ""),
"api_key": (campaignInfo?["api_key"] as? String ?? ""),
"session_uuid": (item.session_uuid ?? ""),
"access_token": (campaignInfo?["access_token"] as? String ?? ""),
"refresh_token": (campaignInfo?["refresh_token"] as? String ?? ""),
"client_id": (campaignInfo?["client_id"] as? String ?? ""),
"client_secret": (campaignInfo?["client_secret"] as? String ?? ""),
"Session_ID": (campaign._sessionId),
"businessService": (campaign._businessService),
"offerName": (campaign._offerName),
"productType": (campaign._productType),
"provDuration": (campaign._provDuration),
"noOfRecurrance": (campaign._noOfRecurrance),
"price": (campaign._price),
"discount": (campaign._discount),
"voiceCategory": (campaign._voiceCategory),
"dataCategory": (campaign._dataCategory),
"minsValue": (campaign._minsValue),
"dataValue": (campaign._dataValue),
"provStepValueMins": (campaign._provStepValueMins),
"UACIOfferTrackingCode": (campaign._uaciOfferTrackingCode),
"OFFERCODE1": (campaign._offerCode1),
"SCORE": (campaign._score),
"WAVE": (campaign._wave),
"VALIDITY": (campaign._validity),
"TREATMENT_CODE": (campaign._treatmentCode),
"OfferAudienceLevel": (campaign._offerAudienceLevel),
"ASSETS": (assetsString),
"ZONE": (campaign._zone)
]
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(jsonObject)
let stringData = String(data: data, encoding: .utf8) ?? ""
print("constructCcmsParams: " + stringData)
return stringData
break;
}
}
print("constructCcmsParams: " + "")
return ""
}
public func constructCcmsParams(_ campaign: CampaignItemModel, _ ccmsCampaign: LoyaltyContextualOfferModel) -> String {
var assetsString = ""
if (ccmsCampaign._eligibleAssets != nil && ccmsCampaign._eligibleAssets.count > 0) {
for (index, item) in ccmsCampaign._eligibleAssets.enumerated() {
if (index == (ccmsCampaign._eligibleAssets.endIndex - 1)) {
assetsString += String(item)
} else {
assetsString += String(item) + ","
}
}
}
let instanceOfMyApi = MyApi()
let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
let jsonObject: [String: String] = [
"web_id": (campaignInfo?["web_id"] as? String ?? ""),
"app_uuid": (campaignInfo?["app_uuid"] as? String ?? ""),
"api_key": (campaignInfo?["api_key"] as? String ?? ""),
"session_uuid": (campaign.session_uuid ?? ""),
"access_token": (campaignInfo?["access_token"] as? String ?? ""),
"refresh_token": (campaignInfo?["refresh_token"] as? String ?? ""),
"client_id": (campaignInfo?["client_id"] as? String ?? ""),
"client_secret": (campaignInfo?["client_secret"] as? String ?? ""),
"Session_ID": (ccmsCampaign._sessionId),
"businessService": (ccmsCampaign._businessService),
"offerName": (ccmsCampaign._offerName),
"productType": (ccmsCampaign._productType),
"provDuration": (ccmsCampaign._provDuration),
"noOfRecurrance": (ccmsCampaign._noOfRecurrance),
"price": (ccmsCampaign._price),
"discount": (ccmsCampaign._discount),
"voiceCategory": (ccmsCampaign._voiceCategory),
"dataCategory": (ccmsCampaign._dataCategory),
"minsValue": (ccmsCampaign._minsValue),
"dataValue": (ccmsCampaign._dataValue),
"provStepValueMins": (ccmsCampaign._provStepValueMins),
"UACIOfferTrackingCode": (ccmsCampaign._uaciOfferTrackingCode),
"OFFERCODE1": (ccmsCampaign._offerCode1),
"SCORE": (ccmsCampaign._score),
"WAVE": (ccmsCampaign._wave),
"VALIDITY": (ccmsCampaign._validity),
"TREATMENT_CODE": (ccmsCampaign._treatmentCode),
"OfferAudienceLevel": (ccmsCampaign._offerAudienceLevel),
"ASSETS": (assetsString),
"ZONE": (ccmsCampaign._zone)
]
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(jsonObject)
let stringData = String(data: data, encoding: .utf8) ?? ""
print("constructCcmsParams: " + stringData)
return stringData
}
public func handleSharing(_ controller: UIViewController, _ sharingId: String) -> Void {
print("SHARING_ID: " + sharingId)
......@@ -2514,7 +2670,9 @@ public class swiftApi {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
let url = swiftApi().constructCampaignUrl(item)
let params = swiftApi().constructCampaignParams(item)
vc.campaignUrl = url
vc.params = params
controller.navigationController?.pushViewController(vc, animated: true)
break;
}
......@@ -2528,8 +2686,10 @@ public class swiftApi {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
let url = swiftApi().constructCampaignUrl(item)
let params = swiftApi().constructCampaignParams(item)
print("openPacing url: " + url)
vc.campaignUrl = url
vc.params = params
controller.navigationController?.pushViewController(vc, animated: true)
break;
}
......@@ -3704,6 +3864,7 @@ public class swiftApi {
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
vc.campaignUrl = swiftApi().constructCampaignUrl(campaign)
vc.params = swiftApi().constructCampaignParams(campaign)
controller.navigationController?.pushViewController(vc, animated: true)
}
}
......@@ -3722,6 +3883,7 @@ public class swiftApi {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
vc.campaignUrl = swiftApi().constructCcmsUrl(loyaltyCampaign, ccms)
vc.params = swiftApi().constructCcmsParams(loyaltyCampaign, ccms)
controller.navigationController?.pushViewController(vc, animated: true)
break;
......