Skip to content

Commit

Permalink
Merge pull request #105 from blueshift-labs/development_version_2.0.6
Browse files Browse the repository at this point in the history
Development version 2.0.6
  • Loading branch information
anwarshahas authored Jan 9, 2020
2 parents 14c2a0d + fb80f85 commit 3de395a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 32 deletions.
81 changes: 49 additions & 32 deletions BlueShift-iOS-SDK/BlueShiftAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];

Expand All @@ -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];
Expand All @@ -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];

Expand All @@ -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];
Expand All @@ -260,7 +260,9 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo {
}
}

[self setupPushNotificationDeeplink: userInfo];
if (![BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) {
[self setupPushNotificationDeeplink: userInfo];
}
}
}

Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -360,18 +362,20 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo forApplicationState:(U
}
}
}

if (![BlueshiftEventAnalyticsHelper isCarouselPushNotificationPayload: userInfo]) {
[self setupPushNotificationDeeplink: userInfo];
}
}
}

[self setupPushNotificationDeeplink: userInfo];
}

- (BOOL)customDeepLinkToPrimitiveCategory {
NSDictionary *pushTrackParameterDictionary = [BlueshiftEventAnalyticsHelper pushTrackParameterDictionaryForPushDetailsDictionary:self.userInfo];
[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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions BlueShift-iOS-SDK/BlueShiftNotificationConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3de395a

Please sign in to comment.