Manos Chorianopoulos

fix UIAlertView sdk error, add test code for push

......@@ -102,6 +102,8 @@
// - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;
- (void)didReceiveNotification:(NSDictionary *)payload;
- (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload;
// TEST CODE FOR PUSH
// - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure;
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
- (void)editProfileAsync:(NSString*)firstname andLastname:(NSString*)lastname andEmail:(NSString *)email andSalutation:(NSString *)salutation andMsisdn:(NSString *)msisdn andNickname:(NSString *)nickname andGender:(NSString *)gender andBirthday:(NSString *)birthday andNameDay:(NSString *)nameday andTaxID:(NSString *)taxid andProfileMetadata:(NSDictionary *)profileMetadata optin:(NSNumber *)optin newsLetter:(NSNumber *)newsletter andSMS:(NSNumber *)sms andSegmentation:(NSNumber *)segmentation andSMSSegmentation:(NSNumber *)smsSegmentation :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getSingleCampaignAsync:(NSString*)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -1616,6 +1616,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload];
}
// TEST CODE FOR PUSH
// - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure {
// return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload :^(NSNumber *successResponse) {
// if (success) {
// success(successResponse);
// }
// } failureBlock:^(NSNumber *failureResponse) {
// if (failure) {
// failure(failureResponse);
// }
// }];
// }
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken {
[[Warply sharedService].pushManager sendDeviceInfoIfNecessary:newDeviceToken];
......
......@@ -37,6 +37,9 @@
- (id)initWithAttributes:(NSDictionary *)attributes
{
self = [super init];
// TODO: check if attributes != nil giati mallon edw skaei to length
if (self) {
NSObject *idx = nil;
for (NSString *key in [attributes allKeys]) {
......
......@@ -162,6 +162,8 @@ typedef enum WLApplicationState : unsigned int{
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;
- (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo;
// TEST CODE FOR PUSH
// - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure;
/*!
@abstract Application received a Remote Notification.
......
......@@ -314,12 +314,37 @@ static const char* jailbreak_apps[] =
switch (state) {
case WLApplicationStateActive:
{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
[alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")];
[alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")];
[alert setDelegate:self];
[alert show];
UIAlertController * alert = [UIAlertController alertControllerWithTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Close", @"Warply")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handle your yes please button action here
}];
UIAlertAction* noButton = [UIAlertAction
actionWithTitle:NSLocalizedString(@"View", @"Warply")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handle no, thanks button
}];
[alert addAction:yesButton];
[alert addAction:noButton];
UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
alertWindow.rootViewController = [[UIViewController alloc] init];
alertWindow.windowLevel = UIWindowLevelAlert + 1;
[alertWindow makeKeyAndVisible];
[alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
// UIAlertView *alert = [[UIAlertView alloc] init];
// [alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
// [alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")];
// [alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")];
// [alert setDelegate:self];
// [alert show];
self.pendingItem = inboxItem;
break;
......@@ -336,6 +361,100 @@ static const char* jailbreak_apps[] =
return YES;
}
// TEST CODE FOR PUSH
// - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure
// {
// // TODO: Check if this guard should be commented
// if ([userInfo valueForKey:@"_a"] == nil) {
// // The push was sent from another push service
// if (failure) {
// failure(@0);
// }
// return NO;
// }
// // TODO: Check if states are correct, especially from didFinishLaunchingWithOptions
// WLApplicationState state;
// if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
// state = WLApplicationStateActive;
// else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive)
// state = WLApplicationStateClosed;
// else
// state = WLApplicationStateBackground;
// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:NSJSONWritingPrettyPrinted error:nil];
// NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// WLLOG(@"Did receive push: %@", jsonString);
// WLInboxItem *inboxItem = [[WLInboxItem alloc] initWithAttributes:userInfo] ;
// // [WLAnalyticsManager logUserReceivedPush:inboxItem];
// if (state != WLApplicationStateActive) {
// [WLAnalyticsManager logUserEngagedPush:inboxItem];
// }
// if (inboxItem.action != 0) {
// [self.customPushHanlder didReceiveRemoteNotification:userInfo whileAppWasInState:state];
// if (success) {
// success(@1);
// }
// return YES;
// }
// switch (state) {
// case WLApplicationStateActive:
// {
// UIAlertController * alert = [UIAlertController alertControllerWithTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] message:@"" preferredStyle:UIAlertControllerStyleAlert];
// UIAlertAction* yesButton = [UIAlertAction
// actionWithTitle:NSLocalizedString(@"Close", @"Warply")
// style:UIAlertActionStyleDefault
// handler:^(UIAlertAction * action) {
// //Handle your yes please button action here
// }];
// UIAlertAction* noButton = [UIAlertAction
// actionWithTitle:NSLocalizedString(@"View", @"Warply")
// style:UIAlertActionStyleDefault
// handler:^(UIAlertAction * action) {
// //Handle no, thanks button
// }];
// [alert addAction:yesButton];
// [alert addAction:noButton];
// UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// alertWindow.rootViewController = [[UIViewController alloc] init];
// alertWindow.windowLevel = UIWindowLevelAlert + 1;
// [alertWindow makeKeyAndVisible];
// [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
// // [self presentViewController:alert animated:YES completion:nil];
// // UIAlertView *alert = [[UIAlertView alloc] init];
// // [alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
// // [alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")];
// // [alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")];
// // [alert setDelegate:self];
// // [alert show];
// self.pendingItem = inboxItem;
// break;
// }
// case WLApplicationStateBackground:
// {
// [self showItem:inboxItem];
// break;
// }
// case WLApplicationStateClosed:
// self.pendingItem = inboxItem;
// break;
// }
// if (success) {
// success(@1);
// }
// return YES;
// }
///////////////////////////////////////////////////////////////////////////////
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
......@@ -515,8 +634,25 @@ static const char* jailbreak_apps[] =
UIViewController *existingModalController = [[UIApplication sharedApplication].delegate.window.rootViewController topModalViewController];
if (existingModalController == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"WL_Warning" message:@"You have to set the mainWindow.rootViewController in order for offer views to be presented properly." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"WL_Warning" message:@"You have to set the mainWindow.rootViewController in order for offer views to be presented properly." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
// [alert show];
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"WL_Warning" message:@"You have to set the mainWindow.rootViewController in order for offer views to be presented properly." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handle your yes please button action here
}];
[alert addAction:yesButton];
UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
alertWindow.rootViewController = [[UIViewController alloc] init];
alertWindow.windowLevel = UIWindowLevelAlert + 1;
[alertWindow makeKeyAndVisible];
[alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
return;
}
......
......@@ -5645,6 +5645,56 @@ public class swiftApi {
let instanceOfMyApi = MyApi()
return instanceOfMyApi.checkforLoyaltySDKNotification(payload)
}
// TEST CODE FOR PUSH
// public func checkForLoyaltySDKNotification(_ payload: [String : Any]) -> Bool {
// let instanceOfMyApi = MyApi()
// return instanceOfMyApi.checkforLoyaltySDKNotification(payload) { response in
// print("LoyaltySDKNotification: successCallback")
// // TODO: Check if session_uuid is provided and Redirect to campaignVC
// // if let sessionUuid = payload["session_uuid"] as? String {
// // print("=== sessionUuid ===")
// // print(sessionUuid)
// // let allCampaigns = swiftApi().getAllCampaignList()
// // print("=== allCampaigns ===")
// // print(allCampaigns)
// // let loyaltyCampaignIdExists = allCampaigns.contains { $0.session_uuid == sessionUuid }
// // print("=== loyaltyCampaignIdExists ===")
// // print(loyaltyCampaignIdExists)
// // for loyaltyCampaign in allCampaigns {
// // if (loyaltyCampaign.session_uuid == sessionUuid) {
// // print("=== sessionUuid Found ===")
// // // let viewController = UIApplication.shared.windows.first!.rootViewController as! YourViewController
// // let viewController = UIApplication.shared.windows.first!.rootViewController!
// // print("=== viewController ===")
// // print(viewController)
// // swiftApi().handleLoyaltyCampaigns(loyaltyCampaign, viewController)
// // break;
// // }
// // }
// // }
// } failureBlock: { response in
// print("LoyaltySDKNotification: The push was sent from another push service")
// }
// }
public func sendDeviceInfoIfNecessary(_ newDeviceToken: String) -> Void {
......