Manos Chorianopoulos

fix UIAlertView sdk error, add test code for push

...@@ -102,6 +102,8 @@ ...@@ -102,6 +102,8 @@
102 // - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; 102 // - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;
103 - (void)didReceiveNotification:(NSDictionary *)payload; 103 - (void)didReceiveNotification:(NSDictionary *)payload;
104 - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload; 104 - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload;
105 +// TEST CODE FOR PUSH
106 +// - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure;
105 - (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken; 107 - (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
106 - (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; 108 - (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;
107 - (void)getSingleCampaignAsync:(NSString*)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 109 - (void)getSingleCampaignAsync:(NSString*)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -1616,6 +1616,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1616,6 +1616,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1616 return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload]; 1616 return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload];
1617 } 1617 }
1618 1618
1619 +// TEST CODE FOR PUSH
1620 +// - (BOOL)checkforLoyaltySDKNotification:(NSDictionary *)payload :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure {
1621 +
1622 +// return [[Warply sharedService].pushManager checkforLoyaltySDKNotificationPM:payload :^(NSNumber *successResponse) {
1623 +// if (success) {
1624 +// success(successResponse);
1625 +// }
1626 +// } failureBlock:^(NSNumber *failureResponse) {
1627 +// if (failure) {
1628 +// failure(failureResponse);
1629 +// }
1630 +// }];
1631 +// }
1632 +
1619 - (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken { 1633 - (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken {
1620 1634
1621 [[Warply sharedService].pushManager sendDeviceInfoIfNecessary:newDeviceToken]; 1635 [[Warply sharedService].pushManager sendDeviceInfoIfNecessary:newDeviceToken];
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
37 - (id)initWithAttributes:(NSDictionary *)attributes 37 - (id)initWithAttributes:(NSDictionary *)attributes
38 { 38 {
39 self = [super init]; 39 self = [super init];
40 +
41 + // TODO: check if attributes != nil giati mallon edw skaei to length
42 +
40 if (self) { 43 if (self) {
41 NSObject *idx = nil; 44 NSObject *idx = nil;
42 for (NSString *key in [attributes allKeys]) { 45 for (NSString *key in [attributes allKeys]) {
......
...@@ -162,6 +162,8 @@ typedef enum WLApplicationState : unsigned int{ ...@@ -162,6 +162,8 @@ typedef enum WLApplicationState : unsigned int{
162 - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; 162 - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;
163 163
164 - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo; 164 - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo;
165 +// TEST CODE FOR PUSH
166 +// - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure;
165 167
166 /*! 168 /*!
167 @abstract Application received a Remote Notification. 169 @abstract Application received a Remote Notification.
......
...@@ -314,12 +314,37 @@ static const char* jailbreak_apps[] = ...@@ -314,12 +314,37 @@ static const char* jailbreak_apps[] =
314 switch (state) { 314 switch (state) {
315 case WLApplicationStateActive: 315 case WLApplicationStateActive:
316 { 316 {
317 - UIAlertView *alert = [[UIAlertView alloc] init]; 317 + UIAlertController * alert = [UIAlertController alertControllerWithTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] message:@"" preferredStyle:UIAlertControllerStyleAlert];
318 - [alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]; 318 +
319 - [alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")]; 319 + UIAlertAction* yesButton = [UIAlertAction
320 - [alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")]; 320 + actionWithTitle:NSLocalizedString(@"Close", @"Warply")
321 - [alert setDelegate:self]; 321 + style:UIAlertActionStyleDefault
322 - [alert show]; 322 + handler:^(UIAlertAction * action) {
323 + //Handle your yes please button action here
324 + }];
325 +
326 + UIAlertAction* noButton = [UIAlertAction
327 + actionWithTitle:NSLocalizedString(@"View", @"Warply")
328 + style:UIAlertActionStyleDefault
329 + handler:^(UIAlertAction * action) {
330 + //Handle no, thanks button
331 + }];
332 +
333 + [alert addAction:yesButton];
334 + [alert addAction:noButton];
335 +
336 + UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
337 + alertWindow.rootViewController = [[UIViewController alloc] init];
338 + alertWindow.windowLevel = UIWindowLevelAlert + 1;
339 + [alertWindow makeKeyAndVisible];
340 + [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
341 +
342 + // UIAlertView *alert = [[UIAlertView alloc] init];
343 + // [alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
344 + // [alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")];
345 + // [alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")];
346 + // [alert setDelegate:self];
347 + // [alert show];
323 348
324 self.pendingItem = inboxItem; 349 self.pendingItem = inboxItem;
325 break; 350 break;
...@@ -336,6 +361,100 @@ static const char* jailbreak_apps[] = ...@@ -336,6 +361,100 @@ static const char* jailbreak_apps[] =
336 return YES; 361 return YES;
337 } 362 }
338 363
364 +// TEST CODE FOR PUSH
365 +// - (BOOL)checkforLoyaltySDKNotificationPM:(NSDictionary *)userInfo :(void(^)(NSNumber *successResponse))success failureBlock:(void(^)(NSNumber *failureResponse))failure
366 +// {
367 +// // TODO: Check if this guard should be commented
368 +// if ([userInfo valueForKey:@"_a"] == nil) {
369 +// // The push was sent from another push service
370 +// if (failure) {
371 +// failure(@0);
372 +// }
373 +// return NO;
374 +// }
375 +
376 +// // TODO: Check if states are correct, especially from didFinishLaunchingWithOptions
377 +// WLApplicationState state;
378 +// if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
379 +// state = WLApplicationStateActive;
380 +// else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive)
381 +// state = WLApplicationStateClosed;
382 +// else
383 +// state = WLApplicationStateBackground;
384 +
385 +
386 +// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:NSJSONWritingPrettyPrinted error:nil];
387 +// NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
388 +// WLLOG(@"Did receive push: %@", jsonString);
389 +// WLInboxItem *inboxItem = [[WLInboxItem alloc] initWithAttributes:userInfo] ;
390 +// // [WLAnalyticsManager logUserReceivedPush:inboxItem];
391 +
392 +// if (state != WLApplicationStateActive) {
393 +// [WLAnalyticsManager logUserEngagedPush:inboxItem];
394 +// }
395 +
396 +// if (inboxItem.action != 0) {
397 +// [self.customPushHanlder didReceiveRemoteNotification:userInfo whileAppWasInState:state];
398 +// if (success) {
399 +// success(@1);
400 +// }
401 +// return YES;
402 +// }
403 +// switch (state) {
404 +// case WLApplicationStateActive:
405 +// {
406 +// UIAlertController * alert = [UIAlertController alertControllerWithTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] message:@"" preferredStyle:UIAlertControllerStyleAlert];
407 +
408 +// UIAlertAction* yesButton = [UIAlertAction
409 +// actionWithTitle:NSLocalizedString(@"Close", @"Warply")
410 +// style:UIAlertActionStyleDefault
411 +// handler:^(UIAlertAction * action) {
412 +// //Handle your yes please button action here
413 +// }];
414 +
415 +// UIAlertAction* noButton = [UIAlertAction
416 +// actionWithTitle:NSLocalizedString(@"View", @"Warply")
417 +// style:UIAlertActionStyleDefault
418 +// handler:^(UIAlertAction * action) {
419 +// //Handle no, thanks button
420 +// }];
421 +
422 +// [alert addAction:yesButton];
423 +// [alert addAction:noButton];
424 +
425 +// UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
426 +// alertWindow.rootViewController = [[UIViewController alloc] init];
427 +// alertWindow.windowLevel = UIWindowLevelAlert + 1;
428 +// [alertWindow makeKeyAndVisible];
429 +// [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
430 +
431 +// // [self presentViewController:alert animated:YES completion:nil];
432 +
433 +// // UIAlertView *alert = [[UIAlertView alloc] init];
434 +// // [alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
435 +// // [alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")];
436 +// // [alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")];
437 +// // [alert setDelegate:self];
438 +// // [alert show];
439 +
440 +// self.pendingItem = inboxItem;
441 +// break;
442 +// }
443 +// case WLApplicationStateBackground:
444 +// {
445 +// [self showItem:inboxItem];
446 +// break;
447 +// }
448 +// case WLApplicationStateClosed:
449 +// self.pendingItem = inboxItem;
450 +// break;
451 +// }
452 +// if (success) {
453 +// success(@1);
454 +// }
455 +// return YES;
456 +// }
457 +
339 /////////////////////////////////////////////////////////////////////////////// 458 ///////////////////////////////////////////////////////////////////////////////
340 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 459 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
341 { 460 {
...@@ -515,8 +634,25 @@ static const char* jailbreak_apps[] = ...@@ -515,8 +634,25 @@ static const char* jailbreak_apps[] =
515 UIViewController *existingModalController = [[UIApplication sharedApplication].delegate.window.rootViewController topModalViewController]; 634 UIViewController *existingModalController = [[UIApplication sharedApplication].delegate.window.rootViewController topModalViewController];
516 635
517 if (existingModalController == nil) { 636 if (existingModalController == nil) {
518 - 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]; 637 + // 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];
519 - [alert show]; 638 + // [alert show];
639 +
640 + 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];
641 +
642 + UIAlertAction* yesButton = [UIAlertAction
643 + actionWithTitle:@"OK"
644 + style:UIAlertActionStyleDefault
645 + handler:^(UIAlertAction * action) {
646 + //Handle your yes please button action here
647 + }];
648 +
649 + [alert addAction:yesButton];
650 +
651 + UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
652 + alertWindow.rootViewController = [[UIViewController alloc] init];
653 + alertWindow.windowLevel = UIWindowLevelAlert + 1;
654 + [alertWindow makeKeyAndVisible];
655 + [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil];
520 656
521 return; 657 return;
522 } 658 }
......
...@@ -5647,6 +5647,56 @@ public class swiftApi { ...@@ -5647,6 +5647,56 @@ public class swiftApi {
5647 } 5647 }
5648 5648
5649 5649
5650 +// TEST CODE FOR PUSH
5651 + // public func checkForLoyaltySDKNotification(_ payload: [String : Any]) -> Bool {
5652 +
5653 + // let instanceOfMyApi = MyApi()
5654 +
5655 + // return instanceOfMyApi.checkforLoyaltySDKNotification(payload) { response in
5656 + // print("LoyaltySDKNotification: successCallback")
5657 + // // TODO: Check if session_uuid is provided and Redirect to campaignVC
5658 +
5659 + // // if let sessionUuid = payload["session_uuid"] as? String {
5660 +
5661 + // // print("=== sessionUuid ===")
5662 + // // print(sessionUuid)
5663 +
5664 + // // let allCampaigns = swiftApi().getAllCampaignList()
5665 +
5666 + // // print("=== allCampaigns ===")
5667 + // // print(allCampaigns)
5668 +
5669 + // // let loyaltyCampaignIdExists = allCampaigns.contains { $0.session_uuid == sessionUuid }
5670 +
5671 + // // print("=== loyaltyCampaignIdExists ===")
5672 + // // print(loyaltyCampaignIdExists)
5673 +
5674 + // // for loyaltyCampaign in allCampaigns {
5675 + // // if (loyaltyCampaign.session_uuid == sessionUuid) {
5676 +
5677 + // // print("=== sessionUuid Found ===")
5678 +
5679 + // // // let viewController = UIApplication.shared.windows.first!.rootViewController as! YourViewController
5680 + // // let viewController = UIApplication.shared.windows.first!.rootViewController!
5681 +
5682 + // // print("=== viewController ===")
5683 + // // print(viewController)
5684 +
5685 + // // swiftApi().handleLoyaltyCampaigns(loyaltyCampaign, viewController)
5686 +
5687 + // // break;
5688 + // // }
5689 + // // }
5690 + // // }
5691 +
5692 +
5693 +
5694 + // } failureBlock: { response in
5695 + // print("LoyaltySDKNotification: The push was sent from another push service")
5696 + // }
5697 + // }
5698 +
5699 +
5650 public func sendDeviceInfoIfNecessary(_ newDeviceToken: String) -> Void { 5700 public func sendDeviceInfoIfNecessary(_ newDeviceToken: String) -> Void {
5651 5701
5652 let instanceOfMyApi = MyApi() 5702 let instanceOfMyApi = MyApi()
......