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,6 +333,12 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
} else {
if (campaigns[indexPath.row].session_uuid != nil && 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 = ""
......@@ -388,6 +394,7 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
} else {
let seasonalEvent = swiftApi.LoyaltyGiftsForYouOfferClickEvent()
......@@ -418,4 +425,24 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
}
}
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,6 +371,10 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
}
} else {
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)
......@@ -436,6 +440,7 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
}
}
}
}
func getSingleCampaignAsyncRequest(sessionUuid: String) {
......@@ -450,4 +455,23 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
}
}
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)
......
......@@ -4031,7 +4031,32 @@ 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 {
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))
......@@ -4046,9 +4071,15 @@ public class swiftApi {
}
}
}
}
public func openPacing(_ controller: UIViewController) -> Void {
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))
......@@ -4064,6 +4095,7 @@ public class swiftApi {
}
}
}
}
public func openCouponset(_ controller: UIViewController) -> Void {
......@@ -5936,6 +5968,11 @@ public class swiftApi {
}
} else {
let status = swiftApi().getNetworkStatus()
if (status == -1 || status == 0) {
swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
swiftApi().logTrackersEvent("click", ("Loyalty:" + (campaign.session_uuid ?? "")))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
......@@ -5949,6 +5986,7 @@ public class swiftApi {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
}
func getSingleCampaignAsyncRequest(sessionUuid: String) {
swiftApi().getSingleCampaignAsync(sessionUuid: sessionUuid, getSingleCampaignCallback)
......@@ -5993,6 +6031,12 @@ public class swiftApi {
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)))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
......@@ -6005,6 +6049,7 @@ public class swiftApi {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
} else if (isTelco && (loyaltyCampaign.session_uuid == ccms._loyaltyCampaignId)) {
......@@ -7242,4 +7287,16 @@ public class swiftApi {
}
/*
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2,
*/
public func getNetworkStatus() -> Int {
let instanceOfMyApi = MyApi()
return instanceOfMyApi.getNetworkStatusM()
}
}
......