Manos Chorianopoulos

add network check

......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -333,60 +333,67 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
} else {
if (campaigns[indexPath.row].session_uuid != nil && campaigns[indexPath.row].session_uuid != "") {
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) {
let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
let loyaltyCampaignIdExists = ccmsCampaigns.contains { $0._loyaltyCampaignId == campaigns[indexPath.row].session_uuid }
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
self.showDialog("Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
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) {
let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
if (loyaltyCampaignIdExists == true) {
var ccmsCampaignFound:swiftApi.LoyaltyContextualOfferModel = swiftApi.LoyaltyContextualOfferModel()
for item in ccmsCampaigns {
if (item._loyaltyCampaignId == campaigns[indexPath.row].session_uuid) {
ccmsCampaignFound = item
let loyaltyCampaignIdExists = ccmsCampaigns.contains { $0._loyaltyCampaignId == campaigns[indexPath.row].session_uuid }
if (loyaltyCampaignIdExists == true) {
var ccmsCampaignFound:swiftApi.LoyaltyContextualOfferModel = swiftApi.LoyaltyContextualOfferModel()
for item in ccmsCampaigns {
if (item._loyaltyCampaignId == campaigns[indexPath.row].session_uuid) {
ccmsCampaignFound = item
}
}
}
swiftApi().logTrackersEvent("click", ("Contextual:" + (ccmsCampaignFound._sessionId)))
url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound)
params = swiftApi().constructCcmsParams(campaigns[indexPath.row], ccmsCampaignFound)
swiftApi().logTrackersEvent("click", ("Contextual:" + (ccmsCampaignFound._sessionId)))
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])
} else {
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
}
}
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaigns[indexPath.row])
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaigns[indexPath.row])
print("CCMS_CLICK " + String(data: data, encoding: .utf8)!)
print("CCMS_CLICK " + String(data: data, encoding: .utf8)!)
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaigns[indexPath.row].session_uuid ?? "")))
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaigns[indexPath.row].session_uuid ?? "")))
url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
params = swiftApi().constructCampaignParams(campaigns[indexPath.row])
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaigns[indexPath.row])
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaigns[indexPath.row])
print("GFY_CLICK " + String(data: data, encoding: .utf8)!)
}
print("CampaignUrl url onclick: " + url)
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
print("GFY_CLICK " + String(data: data, encoding: .utf8)!)
}
print("CampaignUrl url onclick: " + url)
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
} else {
......@@ -417,5 +424,25 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
} else {
}
}
func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
}
......
......@@ -371,68 +371,73 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
}
} else {
// let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
// let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
// let url = swiftApi().constructCampaignUrl(campaign)
// print("CampaignUrl url onclick: " + url)
// vc.campaignUrl = url
// self.navigationController?.pushViewController(vc, animated: true)
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 = (campaign.ccms_offer != nil) && (campaign.ccms_offer != "") && (campaign.ccms_offer == "true")
if (isCcmsOffer) {
let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
self.showDialog("Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
// let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
// let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
// let url = swiftApi().constructCampaignUrl(campaign)
// print("CampaignUrl url onclick: " + url)
// vc.campaignUrl = url
// self.navigationController?.pushViewController(vc, animated: true)
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 = (campaign.ccms_offer != nil) && (campaign.ccms_offer != "") && (campaign.ccms_offer == "true")
if (isCcmsOffer) {
let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
let loyaltyCampaignIdExists = ccmsCampaigns.contains { $0._loyaltyCampaignId == campaign.session_uuid }
let loyaltyCampaignIdExists = ccmsCampaigns.contains { $0._loyaltyCampaignId == campaign.session_uuid }
if (loyaltyCampaignIdExists == true) {
var ccmsCampaignFound:swiftApi.LoyaltyContextualOfferModel = swiftApi.LoyaltyContextualOfferModel()
for item in ccmsCampaigns {
if (item._loyaltyCampaignId == campaign.session_uuid) {
ccmsCampaignFound = item
if (loyaltyCampaignIdExists == true) {
var ccmsCampaignFound:swiftApi.LoyaltyContextualOfferModel = swiftApi.LoyaltyContextualOfferModel()
for item in ccmsCampaigns {
if (item._loyaltyCampaignId == campaign.session_uuid) {
ccmsCampaignFound = item
}
}
}
swiftApi().logTrackersEvent("click", ("Contextual:" + (ccmsCampaignFound._sessionId)))
url = swiftApi().constructCcmsUrl(campaign, ccmsCampaignFound)
params = swiftApi().constructCcmsParams(campaign, ccmsCampaignFound)
swiftApi().logTrackersEvent("click", ("Contextual:" + (ccmsCampaignFound._sessionId)))
url = swiftApi().constructCcmsUrl(campaign, ccmsCampaignFound)
params = swiftApi().constructCcmsParams(campaign, ccmsCampaignFound)
} else {
url = swiftApi().constructCampaignUrl(campaign)
params = swiftApi().constructCampaignParams(campaign)
} else {
url = swiftApi().constructCampaignUrl(campaign)
params = swiftApi().constructCampaignParams(campaign)
}
}
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaign)
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaign)
print("CCMS_CLICK " + String(data: data, encoding: .utf8)!)
print("CCMS_CLICK " + String(data: data, encoding: .utf8)!)
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaign.session_uuid ?? "")))
url = swiftApi().constructCampaignUrl(campaign)
params = swiftApi().constructCampaignParams(campaign)
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaign.session_uuid ?? "")))
url = swiftApi().constructCampaignUrl(campaign)
params = swiftApi().constructCampaignParams(campaign)
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaign)
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(campaign)
print("GFY_CLICK " + String(data: data, encoding: .utf8)!)
}
print("CampaignUrl url onclick: " + url)
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
print("GFY_CLICK " + String(data: data, encoding: .utf8)!)
}
print("CampaignUrl url onclick: " + url)
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
if let sessionUuid = campaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
}
}
......@@ -449,5 +454,24 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
} else {
}
}
func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
}
......
......@@ -117,6 +117,7 @@
- (void) sendEvent: (NSString *) eventName priority: (BOOL) priority;
- (void)updateRefreshTokenMA:(NSString*)access_token :(NSString*)refresh_token;
- (NSString*)getAccessTokenM;
- (long)getNetworkStatusM;
@end
#endif /* MyApi_h */
......
......@@ -1841,4 +1841,10 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
return [[Warply sharedService] getAccessToken2];
}
- (long)getNetworkStatusM
{
return [[Warply sharedService] getNetworkStatus];
}
@end
......
......@@ -471,6 +471,7 @@ WL_VERSION_INTERFACE()
*/
- (void)getInboxStatusWithSuccessBlock:(void (^)(int count, int newItems, int unread))success failureBlock:(void (^)(NSError *error))failure;
- (long)getNetworkStatus;
/*!
@methodgroup Low Level API
......
......@@ -523,6 +523,12 @@ typedef void (^FailureResponse)(NSURLSessionDataTask * _Nullable task, NSError *
// [[Warply sharedService] addEvent:(WLEvent*)event priority:NO];
}
//- (AFNetworkReachabilityStatus)getNetworkStatus
- (long)getNetworkStatus
{
return (long)self.networkStatus;
}
#pragma mark - Public Methods
///////////////////////////////////////////////////////////////////////////////
WL_VERSION_IMPLEMENTATION(WL_VERSION)
......
......@@ -4030,37 +4030,69 @@ public class swiftApi {
}
}
func showDialog(_ controller: UIViewController,_ alertTitle: String, _ alertSubTitle: String) -> Void {
let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
controller.present(alert, animated: true, completion: nil)
}
public func openQuestionnaire(_ controller: UIViewController) -> Void {
for item in GlobalVariables.campaigns {
if (item.offer_category == "questionnaire") {
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
vc.showHeader = false
controller.navigationController?.pushViewController(vc, animated: true)
break;
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
for item in GlobalVariables.campaigns {
if (item.offer_category == "questionnaire") {
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
vc.showHeader = false
controller.navigationController?.pushViewController(vc, animated: true)
break;
}
}
}
}
public func openPacing(_ controller: UIViewController) -> Void {
for item in GlobalVariables.campaigns {
if (item.offer_category == "pacing") {
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, true)
print("openPacing url: " + url)
vc.campaignUrl = url
vc.params = params
vc.showHeader = false
controller.navigationController?.pushViewController(vc, animated: true)
break;
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
for item in GlobalVariables.campaigns {
if (item.offer_category == "pacing") {
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, true)
print("openPacing url: " + url)
vc.campaignUrl = url
vc.params = params
vc.showHeader = false
controller.navigationController?.pushViewController(vc, animated: true)
break;
}
}
}
}
......@@ -5936,17 +5968,23 @@ public class swiftApi {
}
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaign.session_uuid ?? "")))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
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)
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
if let sessionUuid = campaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaign.session_uuid ?? "")))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
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)
if let sessionUuid = campaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
}
......@@ -5992,19 +6030,26 @@ public class swiftApi {
let isTelco = (loyaltyCampaign._type != nil && loyaltyCampaign._type == "telco")
if (isCcmsOffer && (loyaltyCampaign.session_uuid == ccms._loyaltyCampaignId)) {
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
swiftApi().logTrackersEvent("click", ("Contextual:" + (ccms._sessionId)))
swiftApi().logTrackersEvent("click", ("Contextual:" + (ccms._sessionId)))
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)
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)
if let sessionUuid = loyaltyCampaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
if let sessionUuid = loyaltyCampaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
break;
} else if (isTelco && (loyaltyCampaign.session_uuid == ccms._loyaltyCampaignId)) {
......@@ -7240,6 +7285,18 @@ public class swiftApi {
successCallback(nil)
}
}
/*
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2,
*/
public func getNetworkStatus() -> Int {
let instanceOfMyApi = MyApi()
return instanceOfMyApi.getNetworkStatusM()
}
}
......