diff --git a/BlueShift-iOS-SDK/BlueShiftAppDelegate.m b/BlueShift-iOS-SDK/BlueShiftAppDelegate.m index f8a3f11c..45818074 100755 --- a/BlueShift-iOS-SDK/BlueShiftAppDelegate.m +++ b/BlueShift-iOS-SDK/BlueShiftAppDelegate.m @@ -167,16 +167,16 @@ - (void)application:(UIApplication *)application handleLocalNotification:(nonnul - (void)scheduleLocalNotification:(NSDictionary *)userInfo { UILocalNotification* localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:600]; - localNotification.alertBody = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]; + localNotification.alertBody = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationAlertIdentifierKey]; localNotification.timeZone = [NSTimeZone defaultTimeZone]; if (@available(iOS 8.0, *)) { - localNotification.category = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; + localNotification.category = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; } - localNotification.soundName = [[userInfo objectForKey:@"aps"] objectForKey:@"sound"]; + localNotification.soundName = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationSoundIdentifierKey]; NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init]; dictionary = [userInfo mutableCopy]; - if([dictionary objectForKey:@"bsft_message_uuid"] == (id)[NSNull null]) { - [dictionary removeObjectForKey:@"bsft_message_uuid"]; + if([dictionary objectForKey: kInAppNotificationModalMessageUDIDKey] == (id)[NSNull null]) { + [dictionary removeObjectForKey: kInAppNotificationModalMessageUDIDKey]; } localNotification.userInfo = dictionary; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; @@ -195,8 +195,8 @@ - (void)presentInAppAlert:(NSDictionary *)userInfo { } - (void)handleLocalNotification:(NSDictionary *)userInfo forApplicationState:(UIApplicationState)applicationState { - NSString *pushCategory = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; - self.pushAlertDictionary = [userInfo objectForKey:@"aps"]; + NSString *pushCategory = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; + self.pushAlertDictionary = [userInfo objectForKey: kNotificationAPSIdentifierKey]; self.userInfo = userInfo; NSDictionary *pushTrackParameterDictionary = [BlueshiftEventAnalyticsHelper pushTrackParameterDictionaryForPushDetailsDictionary:userInfo]; @@ -214,9 +214,9 @@ - (void)handleLocalNotification:(NSDictionary *)userInfo forApplicationState:(UI [self handleCategoryForPromotionUsingPushDetailsDictionary:userInfo]; } else { - NSString *categoryName = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; + NSString *categoryName = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; if(categoryName !=nil && ![categoryName isEqualToString:@""]) { - if([categoryName isEqualToString:@"carousel"] || [categoryName isEqualToString:@"carousel_animation"]) { + if([BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) { [self handleCarouselPushForCategory:categoryName usingPushDetailsDictionary:userInfo]; } else { [self handleCustomCategory:categoryName UsingPushDetailsDictionary:userInfo]; @@ -234,8 +234,8 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo { if ([BlueshiftEventAnalyticsHelper isInAppMessagePayload: userInfo]) { [[BlueShift sharedInstance] createInAppNotification: userInfo forApplicationState: UIApplicationStateActive]; } else { - NSString *pushCategory = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; - self.pushAlertDictionary = [userInfo objectForKey:@"aps"]; + NSString *pushCategory = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; + self.pushAlertDictionary = [userInfo objectForKey: kNotificationAPSIdentifierKey]; self.userInfo = userInfo; NSDictionary *pushTrackParameterDictionary = [BlueshiftEventAnalyticsHelper pushTrackParameterDictionaryForPushDetailsDictionary:userInfo]; @@ -247,9 +247,9 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo { [self handleCategoryForPromotionUsingPushDetailsDictionary:userInfo]; } else { - NSString *categoryName = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; + NSString *categoryName = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; if(categoryName !=nil && ![categoryName isEqualToString:@""]) { - if([categoryName isEqualToString:@"carousel"] || [categoryName isEqualToString:@"carousel_animation"]) { + if([BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) { [self handleCarouselPushForCategory:categoryName usingPushDetailsDictionary:userInfo]; } else { [self handleCustomCategory:categoryName UsingPushDetailsDictionary:userInfo]; @@ -260,7 +260,9 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo { } } - [self setupPushNotificationDeeplink: userInfo]; + if (![BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) { + [self setupPushNotificationDeeplink: userInfo]; + } } } @@ -296,8 +298,8 @@ - (UIViewController *)topViewController:(UIViewController *)rootViewController } - (void)handleRemoteNotification:(NSDictionary *)userInfo forApplicationState:(UIApplicationState)applicationState { - NSString *pushCategory = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; - self.pushAlertDictionary = [userInfo objectForKey:@"aps"]; + NSString *pushCategory = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; + self.pushAlertDictionary = [userInfo objectForKey: kNotificationAPSIdentifierKey]; self.userInfo = userInfo; NSDictionary *pushTrackParameterDictionary = [BlueshiftEventAnalyticsHelper pushTrackParameterDictionaryForPushDetailsDictionary:userInfo]; @@ -308,7 +310,7 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo forApplicationState:(U // Track notification view when app is open ... [self trackPushViewedWithParameters:pushTrackParameterDictionary]; - if([[userInfo objectForKey:@"notification_type"] isEqualToString:@"alert"]) { + if([[userInfo objectForKey: kNotificationTypeIdentifierKey] isEqualToString: kNotificationAlertIdentifierKey]) { // Handle push notification when the app is in active state... UIViewController *topViewController = [self topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]]; BlueShiftAlertView *pushNotificationAlertView = [[BlueShiftAlertView alloc] init]; @@ -342,15 +344,15 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo forApplicationState:(U [self handleCategoryForPromotionUsingPushDetailsDictionary:userInfo]; } else { - NSString *categoryName = [[userInfo objectForKey:@"aps"] objectForKey:@"category"]; + NSString *categoryName = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; if(categoryName !=nil && ![categoryName isEqualToString:@""]) { - if([categoryName isEqualToString:@"carousel"] || [categoryName isEqualToString:@"carousel_animation"]) { + if([BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) { [self handleCarouselPushForCategory:categoryName usingPushDetailsDictionary:userInfo]; } else { [self handleCustomCategory:categoryName UsingPushDetailsDictionary:userInfo]; } } else { - NSString *urlString = [self.userInfo objectForKey:@"deep_link_url"]; + NSString *urlString = [self.userInfo objectForKey: kPushNotificationDeepLinkURLKey]; NSURL *url = [NSURL URLWithString:urlString]; if(url) { [self handleCustomCategory:@"" UsingPushDetailsDictionary:userInfo]; @@ -360,10 +362,12 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo forApplicationState:(U } } } + + if (![BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) { + [self setupPushNotificationDeeplink: userInfo]; + } } } - - [self setupPushNotificationDeeplink: userInfo]; } - (BOOL)customDeepLinkToPrimitiveCategory { @@ -371,7 +375,7 @@ - (BOOL)customDeepLinkToPrimitiveCategory { [self trackPushClickedWithParameters:pushTrackParameterDictionary]; - NSString *urlString = [self.userInfo objectForKey:@"deep_link_url"]; + NSString *urlString = [self.userInfo objectForKey: kPushNotificationDeepLinkURLKey]; NSURL *url = [NSURL URLWithString:urlString]; if(url != nil) { @@ -392,7 +396,7 @@ - (BOOL)customDeepLinkToPrimitiveCategory { [self.blueShiftPushParamDelegate handlePushDictionary:self.userInfo]; } if ([self.blueShiftPushParamDelegate respondsToSelector:@selector(fetchProductID:)]) { - NSString *productID = [self.userInfo objectForKey:@"product_id"]; + NSString *productID = [self.userInfo objectForKey: kNotificationProductIDIdenfierKey]; [self.blueShiftPushParamDelegate fetchProductID:productID]; } return true; @@ -425,7 +429,7 @@ - (void)handleCategoryForBuyUsingPushDetailsDictionary:(NSDictionary *)pushDetai [self.blueShiftPushParamDelegate handlePushDictionary:pushDetailsDictionary]; } if ([self.blueShiftPushParamDelegate respondsToSelector:@selector(fetchProductID:)]) { - NSString *productID = [pushDetailsDictionary objectForKey:@"product_id"]; + NSString *productID = [pushDetailsDictionary objectForKey: kNotificationProductIDIdenfierKey]; [self.blueShiftPushParamDelegate fetchProductID:productID]; } } @@ -496,15 +500,17 @@ - (void)handleCarouselPushForCategory:(NSString *)categoryName usingPushDetailsD [self trackPushClickedWithParameters:pushTrackParameterDictionary]; NSString *bundleIdentifier = [BlueShift sharedInstance].config.appGroupID; if(bundleIdentifier!=(id)[NSNull null] && ![bundleIdentifier isEqualToString:@""]) { - NSUserDefaults *myDefaults = [[NSUserDefaults alloc] + NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:bundleIdentifier]; - NSNumber *selectedIndex = [myDefaults objectForKey:@"selected_index"]; + NSNumber *selectedIndex = [userDefaults objectForKey: kNotificationSelectedIndexKey]; if (selectedIndex != nil) { + [self resetUserDefaults: userDefaults]; + NSInteger index = [selectedIndex integerValue]; index = (index > 0) ? index : 0; - NSArray *carouselItems = [pushDetailsDictionary objectForKey:@"carousel_elements"]; + NSArray *carouselItems = [pushDetailsDictionary objectForKey: kNotificationCarouselElementIdentifierKey]; NSDictionary *selectedItem = [carouselItems objectAtIndex:index]; - NSString *urlString = [selectedItem objectForKey:@"deep_link_url"]; + NSString *urlString = [selectedItem objectForKey: kPushNotificationDeepLinkURLKey]; NSURL *url = [NSURL URLWithString:urlString]; if ([self.blueShiftPushDelegate respondsToSelector:@selector(handleCarouselPushForCategory: clickedWithIndex: withDetails:)]) { // User already implemented the viewPushActionWithDetails in App Delegate... @@ -532,9 +538,20 @@ - (void)handleCarouselPushForCategory:(NSString *)categoryName usingPushDetailsD } [self setupPushNotificationDeeplink: selectedItem]; + } else { + + [self setupPushNotificationDeeplink: pushDetailsDictionary]; } } +} + +- (void)resetUserDefaults:(NSUserDefaults *)userDefaults { + NSDictionary * dict = [userDefaults dictionaryRepresentation]; + for (id key in dict) { + [userDefaults removeObjectForKey:key]; + } + [userDefaults synchronize]; } - (void)handleCustomCategory:(NSString *)categoryName UsingPushDetailsDictionary:(NSDictionary *)pushDetailsDictionary { @@ -550,7 +567,7 @@ - (void)handleCustomCategory:(NSString *)categoryName UsingPushDetailsDictionary } else { // Handle the View Action in SDK ... - NSString *urlString = [pushDetailsDictionary objectForKey:@"deep_link_url"]; + NSString *urlString = [pushDetailsDictionary objectForKey: kPushNotificationDeepLinkURLKey]; NSURL *url = [NSURL URLWithString:urlString]; if(url != nil) { @@ -601,7 +618,7 @@ - (void)handleActionForBuyUsingPushDetailsDictionary:(NSDictionary *)pushDetails [self.blueShiftPushParamDelegate handlePushDictionary:pushDetailsDictionary]; } if ([self.blueShiftPushParamDelegate respondsToSelector:@selector(fetchProductID:)]) { - NSString *productID = [pushDetailsDictionary objectForKey:@"product_id"]; + NSString *productID = [pushDetailsDictionary objectForKey: kNotificationProductIDIdenfierKey]; [self.blueShiftPushParamDelegate fetchProductID:productID]; } } else { @@ -654,7 +671,7 @@ - (void)handleActionForCustomPageForIdentifier:(NSString *)identifier UsingPushD } else { // Handle the View Action in SDK ... - NSString *urlString = [pushDetailsDictionary objectForKey:@"deep_link_url"]; + NSString *urlString = [pushDetailsDictionary objectForKey: kPushNotificationDeepLinkURLKey]; NSURL *url = [NSURL URLWithString:urlString]; if(url != nil) { diff --git a/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h b/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h index 9d169082..53cc17bd 100755 --- a/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h +++ b/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h @@ -8,6 +8,13 @@ #ifndef BlueShift_iOS_SDK_BlueShiftNotificationConstants_h #define BlueShift_iOS_SDK_BlueShiftNotificationConstants_h +#define kNotificationAPSIdentifierKey @"aps" +#define kNotificationAlertIdentifierKey @"alert" +#define kNotificationCategoryIdentifierKey @"category" +#define kNotificationSoundIdentifierKey @"sound" +#define kNotificationTypeIdentifierKey @"notification_type" +#define kNotificationCarouselElementIdentifierKey @"carousel_elements" + #define kNotificationCategoryBuyIdentifier @"buy" #define kNotificationActionBuyIdentifier @"buy" #define kNotificationActionViewIdentifier @"view" @@ -16,6 +23,8 @@ #define kNotificationActionOpenCartIdentifier @"open_cart" #define kNotificationCategoryOfferIdentifier @"promotion" +#define kNotificationProductIDIdenfierKey @"product_id" +#define kNotificationSelectedIndexKey @"selected_index" #define kNotificationOneButtonAlertIdentifier @"alert_box_1_button" #define kNotificationTwoButtonAlertIdentifier @"alert_box" diff --git a/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.h b/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.h index 89131a18..adb0b7af 100644 --- a/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.h +++ b/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.h @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)isSendPushAnalytics:(NSDictionary *)userInfo; + (BOOL)isSilentPushNotification:(NSDictionary *)userInfo; + (BOOL) isInAppMessagePayload: (NSDictionary*)userInfo; ++ (BOOL)isCarouselPushNotificationPayload:(NSDictionary *)userInfo; @end diff --git a/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.m b/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.m index 4dd0fcb6..cb63306e 100644 --- a/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.m +++ b/BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.m @@ -90,4 +90,15 @@ + (BOOL) isInAppMessagePayload: (NSDictionary*)userInfo { return isIAMPayloadPresent; } ++ (BOOL)isCarouselPushNotificationPayload:(NSDictionary *)userInfo { + if (userInfo != nil) { + NSString *categoryName = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey]; + if(categoryName !=nil && ![categoryName isEqualToString:@""]) { + return ([categoryName isEqualToString: kNotificationCarouselIdentifier] || [categoryName isEqualToString: kNotificationCarouselAnimationIdentifier]); + } + } + + return false; +} + @end