Skip to content

Commit

Permalink
Merge pull request #208 from blueshift-labs/release/v2.1.18
Browse files Browse the repository at this point in the history
Release/v2.1.18
  • Loading branch information
ketanshikharebsft committed Jun 15, 2021
2 parents 2ee1142 + dcc9a0e commit 377a223
Show file tree
Hide file tree
Showing 27 changed files with 655 additions and 311 deletions.
2 changes: 2 additions & 0 deletions BlueShift-iOS-Extension-SDK/BlueShiftPushAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ + (void)sendPushAnalytics:(NSString *)type withParams:(NSDictionary *)userInfo {
[parameterMutableDictionary addEntriesFromDictionary:pushTrackParameterDictionary];
}
[parameterMutableDictionary setObject:type forKey:@"a"];
NSString *browserPlatform = [NSString stringWithFormat:@"%@ %@", kiOS, [[UIDevice currentDevice] systemVersion]];
[parameterMutableDictionary setObject:browserPlatform forKey:kBrowserPlatform];
NSString *url = [NSString stringWithFormat:@"%@%@", kBaseURL, kPushEventsUploadURL];
[self fireAPICallWithURL:url data:parameterMutableDictionary andRetryCount:3];
}
Expand Down
2 changes: 1 addition & 1 deletion BlueShift-iOS-Extension-SDK/BlueShiftPushNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (NSArray *)integratePushNotificationWithMediaAttachementsForRequest:(UNNotific
NSLog(@"[Blueshift] Error - Please set the api key in the Notification Service Extension, otherwise push notification delivered events will not reflect on the dashboard");
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self trackPushViewedWithRequest:request];
});

Expand Down
2 changes: 2 additions & 0 deletions BlueShift-iOS-Extension-SDK/BlueshiftExtensionConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@

#define kAppName @"app_name"
#define kDeviceID @"device_id"
#define kBrowserPlatform @"browser_platform"
#define kiOS @"iOS"

#endif
3 changes: 3 additions & 0 deletions BlueShift-iOS-SDK/BlueShift.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ NS_ASSUME_NONNULL_BEGIN
@property BlueShiftAppDelegate * _Nullable appDelegate;
@property BlueShiftUserNotificationCenterDelegate * _Nullable userNotificationDelegate;

/// Image cache for storing downloaded images from the in-app notifications. The cache will be cleared when in-app gets dismissed.
@property (nonatomic, strong) NSCache<NSString*, NSData *> *inAppImageDataCache;

+ (instancetype _Nullable)sharedInstance;

/// Initialise the SDK using BlueShiftConfig
Expand Down
8 changes: 5 additions & 3 deletions BlueShift-iOS-SDK/BlueShift.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ - (void) setupWithConfiguration:(BlueShiftConfig *)config {
}
if (config.enablePushNotification == YES) {
[blueShiftAppDelegate registerForNotification];
[blueShiftAppDelegate handleRemoteNotificationOnLaunchWithLaunchOptions:config.applicationLaunchOptions];
} else if (config.enableSilentPushNotification == YES) {
[blueShiftAppDelegate registerForSilentPushNotification];
}
[blueShiftAppDelegate handleRemoteNotificationOnLaunchWithLaunchOptions:config.applicationLaunchOptions];

// Initialize In App Manager
_inAppNotificationMananger = [[BlueShiftInAppNotificationManager alloc] init];
if (config.inAppNotificationDelegate) {
Expand Down Expand Up @@ -666,10 +667,11 @@ - (void)performRequestQueue:(NSMutableDictionary *)parameters canBatchThisEvent:
if([self validateSDKTrackingRequirements] == false) {
return;
}

if (parameters != nil) {
NSMutableDictionary* mutableParams = [parameters mutableCopy];
[mutableParams setValue:[BlueShiftDeviceData currentDeviceData].operatingSystem forKey:kBrowserPlatform];
NSString *url = [NSString stringWithFormat:@"%@%@", kBaseURL, kPushEventsUploadURL];
BlueShiftRequestOperation *requestOperation = [[BlueShiftRequestOperation alloc] initWithRequestURL:url andHttpMethod:BlueShiftHTTPMethodGET andParameters:[parameters copy] andRetryAttemptsCount:kRequestTryMaximumLimit andNextRetryTimeStamp:0 andIsBatchEvent:isBatchEvent];
BlueShiftRequestOperation *requestOperation = [[BlueShiftRequestOperation alloc] initWithRequestURL:url andHttpMethod:BlueShiftHTTPMethodGET andParameters:[mutableParams copy] andRetryAttemptsCount:kRequestTryMaximumLimit andNextRetryTimeStamp:0 andIsBatchEvent:isBatchEvent];
[BlueShiftRequestQueue addRequestOperation:requestOperation];
}
}
Expand Down
29 changes: 21 additions & 8 deletions BlueShift-iOS-SDK/BlueShiftAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

@implementation BlueShiftAppDelegate
@implementation BlueShiftAppDelegate {
NSString *lastProcessedPushNotificationUUID;
}

- (id) init {
self = [super init];
Expand Down Expand Up @@ -78,12 +80,11 @@ - (void)registerForSilentPushNotification {

// Handles the push notification payload when the app is killed and lauched from push notification tray ...
- (BOOL)handleRemoteNotificationOnLaunchWithLaunchOptions:(NSDictionary *)launchOptions {
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (userInfo) {
// Handling the push notification if we get the userInfo from launchOptions ...
// It's the only way to track notification payload while app is on launch (i.e after the app is killed) ...
[self handleRemoteNotification:userInfo];
if (launchOptions) {
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
[self handleRemoteNotification:userInfo];
}
}

return YES;
Expand Down Expand Up @@ -378,7 +379,12 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo {
if ([BlueshiftEventAnalyticsHelper isSilenPushNotificationPayload: userInfo]) {
[[BlueShift sharedInstance] handleSilentPushNotification: userInfo forApplicationState: UIApplicationStateActive];
} else {
NSString *pushUUID = [userInfo valueForKey:kInAppNotificationModalMessageUDIDKey];
NSString *pushCategory = [[userInfo objectForKey: kNotificationAPSIdentifierKey] objectForKey: kNotificationCategoryIdentifierKey];
if ([pushCategory isEqualToString:kNotificationCategorySilentPushIdentifier] || [pushUUID isEqualToString:lastProcessedPushNotificationUUID]) {
[BlueshiftLog logInfo:@"Skipped processing notification due to one of the following reasons." withDetails:@"1. The push notification is silent push notification 2. The push notification click is already processed." methodName:nil];
return;
}
self.pushAlertDictionary = [userInfo objectForKey: kNotificationAPSIdentifierKey];
self.userInfo = userInfo;
NSDictionary *pushTrackParameterDictionary = [BlueshiftEventAnalyticsHelper pushTrackParameterDictionaryForPushDetailsDictionary:userInfo];
Expand Down Expand Up @@ -416,6 +422,8 @@ - (void)setupPushNotificationDeeplink:(NSDictionary *)userInfo {
[[[BlueShift sharedInstance].config blueShiftPushDelegate] pushNotificationDidClick:userInfo];
}

lastProcessedPushNotificationUUID = [userInfo valueForKey:kInAppNotificationModalMessageUDIDKey];

[self trackAppOpenWithParameters:userInfo];

if (userInfo != nil && ([userInfo objectForKey: kPushNotificationDeepLinkURLKey] || [userInfo objectForKey: kNotificationURLElementKey])) {
Expand All @@ -425,7 +433,7 @@ - (void)setupPushNotificationDeeplink:(NSDictionary *)userInfo {
}
if ([self.oldDelegate respondsToSelector:@selector(application:openURL:options:)]) {
if (@available(iOS 9.0, *)) {
NSDictionary *pushOptions = @{openURLOptionsSource:openURLOptionsBlueshift,openURLOptionsChannel:openURLOptionsPush};
NSDictionary *pushOptions = @{openURLOptionsSource:openURLOptionsBlueshift,openURLOptionsChannel:openURLOptionsPush,openURLOptionsPushUserInfo:userInfo};
[self.oldDelegate application:[UIApplication sharedApplication] openURL: deepLinkURL options:pushOptions];
[BlueshiftLog logInfo:[NSString stringWithFormat:@"%@ %@",@"Delivered push notification deeplink to AppDelegate openURL method, Deep link - ", [deepLinkURL absoluteString]] withDetails: pushOptions methodName:nil];
}
Expand Down Expand Up @@ -473,6 +481,11 @@ - (void)handleRemoteNotification:(NSDictionary *)userInfo forApplicationState:(U
} else if([BlueshiftEventAnalyticsHelper isSchedulePushNotification:userInfo]) {
[self validateAndScheduleLocalNotification:userInfo];
} else {
NSString *pushUUID = [userInfo valueForKey:kInAppNotificationModalMessageUDIDKey];
if ([pushCategory isEqualToString:kNotificationCategorySilentPushIdentifier] || [pushUUID isEqualToString:lastProcessedPushNotificationUUID]) {
[BlueshiftLog logInfo:@"Skipped processing notification due to following reasons" withDetails:@"1. The push notification is silent push notification 2. The push notification click is already processed." methodName:nil];
return;
}
// Handle push notification when the app is in inactive or background state ...
if ([pushCategory isEqualToString:kNotificationCategoryBuyIdentifier]) {
[self handleCategoryForBuyUsingPushDetailsDictionary:userInfo];
Expand Down
1 change: 1 addition & 0 deletions BlueShift-iOS-SDK/BlueShiftNotificationConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define kNotificationCategoryViewCartIdentifier @"view_cart"
#define kNotificationActionOpenCartIdentifier @"open_cart"

#define kNotificationCategorySilentPushIdentifier @"silent push"
#define kNotificationCategoryOfferIdentifier @"promotion"
#define kNotificationProductIDIdenfierKey @"product_id"
#define kNotificationSelectedIndexKey @"selected_index"
Expand Down
31 changes: 16 additions & 15 deletions BlueShift-iOS-SDK/BlueShiftUserInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,48 @@

/// Set user email id.
/// Make sure you call BlueShiftUserInfo.sharedInstance()?.save() after setting/modifying any property of user info.
@property (nonatomic, strong) NSString *email;
@property (nonatomic, strong) NSString* _Nullable email;

/// Set user customer id.
/// Make sure you call BlueShiftUserInfo.sharedInstance()?.save() after setting/modifying any property of user info.
@property (nonatomic, strong) NSString *retailerCustomerID;
@property (nonatomic, strong) NSString* _Nullable retailerCustomerID;

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSString* _Nullable name;
@property (nonatomic, strong) NSString* _Nullable firstName;
@property (nonatomic, strong) NSString* _Nullable lastName;

@property (nonatomic, strong) NSDate *dateOfBirth;
@property (nonatomic, strong) NSString *gender;
@property (nonatomic, strong) NSString *education;
@property (nonatomic, strong) NSDate* _Nullable dateOfBirth;
@property (nonatomic, strong) NSString* _Nullable gender;
@property (nonatomic, strong) NSString* _Nullable education;

@property (nonatomic, strong) NSDate *joinedAt;
@property (nonatomic, strong) NSDate* _Nullable joinedAt;

@property (nonatomic, strong) NSString *facebookID;
@property (nonatomic, strong) NSString* _Nullable facebookID;

/// Unsubscribe from the push notifications.
@property BOOL unsubscribed;
/// Set this flag to true if you want to stop receiving push notifications for that user.
@property NSNumber* _Nullable unsubscribed;

/// The data stored in the additionalUserInfo will be populated on server with `additional_user_info__` prefix to every key name.
/// If key is stored as `profession`, then server will popluate it as `additional_user_info__profession` in the events.
/// Make sure you call BlueShiftUserInfo.sharedInstance()?.save() after setting/modifying the user info.
@property NSDictionary *additionalUserInfo;
@property NSMutableDictionary* _Nullable additionalUserInfo;

/// The data stored in the extras will be sent to server as it is as part of every event.
/// If key is stored as `profession`, then server will populate it as `profession` in the events.
/// Make sure you call BlueShiftUserInfo.sharedInstance()?.save() after setting/modifying the user info.
@property NSDictionary *extras;
@property NSMutableDictionary* _Nullable extras;

/// Call save method after making any change in the BlueshiftUserInfo data to store the data.
- (void)save;

/// Use this method to erase the stored data.
+ (void)removeCurrentUserInfo;

+ (instancetype) sharedInstance;
+ (instancetype _Nullable) sharedInstance;

/// Returns saved User info as dictionary of key value pairs
- (NSDictionary *)toDictionary;
- (NSDictionary *_Nonnull)toDictionary;

@end

8 changes: 5 additions & 3 deletions BlueShift-iOS-SDK/BlueShiftUserInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ - (NSMutableDictionary *)convertToDictionary {
}
[BlueshiftEventAnalyticsHelper addToDictionary:sharedUserInfoMutableDictionary key:kBSUserFacebookId value:self.facebookID];
[BlueshiftEventAnalyticsHelper addToDictionary:sharedUserInfoMutableDictionary key:kBSUserEducation value:self.education];
[BlueshiftEventAnalyticsHelper addToDictionary:sharedUserInfoMutableDictionary key:kBSUserUnsubscribedPush value:[NSNumber numberWithBool:self.unsubscribed]];
if (self.unsubscribed != nil) {
[BlueshiftEventAnalyticsHelper addToDictionary:sharedUserInfoMutableDictionary key:kBSUserUnsubscribedPush value:self.unsubscribed];
}
[BlueshiftEventAnalyticsHelper addToDictionary:sharedUserInfoMutableDictionary key:kBSUserAdditionalInfo value:self.additionalUserInfo];
if (self.dateOfBirth) {
NSNumber *dateOfBirthTimeStamp = [NSNumber numberWithDouble:[self.dateOfBirth timeIntervalSinceReferenceDate]];
Expand Down Expand Up @@ -136,8 +138,8 @@ + (BlueShiftUserInfo *)parseUserInfoDictionary:(NSDictionary *)currentUserInfoDi
blueShiftUserInfo.education = [currentUserInfoDictionary objectForKey:kBSUserEducation];
blueShiftUserInfo.facebookID = [currentUserInfoDictionary objectForKey:kBSUserFacebookId];
blueShiftUserInfo.gender = [currentUserInfoDictionary objectForKey:kBSUserGender];
if([currentUserInfoDictionary objectForKey:kBSUserUnsubscribedPush]) {
blueShiftUserInfo.unsubscribed = [[currentUserInfoDictionary objectForKey:kBSUserUnsubscribedPush] boolValue];
if([currentUserInfoDictionary objectForKey:kBSUserUnsubscribedPush] != nil) {
blueShiftUserInfo.unsubscribed = (NSNumber*)[currentUserInfoDictionary objectForKey:kBSUserUnsubscribedPush];
}
NSTimeInterval joinedAtTimeStamp = [[currentUserInfoDictionary objectForKey:kBSUserJoinedAt] doubleValue];

Expand Down
2 changes: 2 additions & 0 deletions BlueShift-iOS-SDK/BlueshiftConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define kDeviceID @"device_id"
#define kApple @"apple"
#define kiOS @"iOS"
#define kBrowserPlatform @"browser_platform"

//App Data
#define kEnablePush @"enable_push"
Expand Down Expand Up @@ -64,6 +65,7 @@
#define openURLOptionsInAppType @"inAppType"
#define openURLOptionsButtonIndex @"clickedButtonIndex"
#define openURLOptionsButtonText @"clickedButtonText"
#define openURLOptionsPushUserInfo @"userInfo"

//Core data entities
#define kHttpRequestOperationEntity @"HttpRequestOperationEntity"
Expand Down
5 changes: 5 additions & 0 deletions BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ NS_ASSUME_NONNULL_BEGIN
/// Check for nil and add the key value to the given dictionary
+ (void)addToDictionary:(NSMutableDictionary*)dictionary key:(NSString*)key value:(id)value;


/// Returns true if string is not nil and not empty.
/// @param string string to perform check
+ (BOOL)isNotNilAndNotEmpty:(NSString*)string;

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions BlueShift-iOS-SDK/BlueshiftEventAnalyticsHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ + (NSMutableDictionary *)getQueriesFromURL:(NSURL *)URL {
}

+(BOOL)isNotNilAndNotEmpty:(NSString*)string {
if (string && ![string isEqualToString:@""]) {
return YES;
@try {
if (string && ![string isEqualToString:@""]) {
return YES;
}
} @catch (NSException *exception) {
[BlueshiftLog logException:exception withDescription:nil methodName:[NSString stringWithUTF8String:__PRETTY_FUNCTION__]];
}
return NO;
}
Expand Down
4 changes: 2 additions & 2 deletions BlueShift-iOS-SDK/BlueshiftLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ + (void)logException:(NSException*) exception withDescription:(NSString*)descrip
}

+ (void)logInfo:(NSString*)info withDetails: (id) details methodName:(NSString*)method{
if ([[BlueShift sharedInstance] config].debug) {
if ([BlueShift sharedInstance].config && [BlueShift sharedInstance].config.debug) {
NSString* log = @"[Blueshift] info : ";
@try {
if (info) {
Expand All @@ -69,7 +69,7 @@ + (void)logInfo:(NSString*)info withDetails: (id) details methodName:(NSString*)
}

+(void)logAPICallInfo:(NSString*)info withDetails: (NSDictionary*) details statusCode:(NSInteger)statusCode {
if ([[BlueShift sharedInstance] config].debug) {
if ([BlueShift sharedInstance].config && [BlueShift sharedInstance].config.debug) {
NSString* log = @"[Blueshift] API call info : ";
@try {
if (info) {
Expand Down
2 changes: 1 addition & 1 deletion BlueShift-iOS-SDK/InApps/BlueShiftInAppNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign, readwrite) float height;
@property (nonatomic, assign, readwrite) float width;;
@property (nonatomic, assign, readwrite) BOOL enableBackgroundAction;
@property (nonatomic, assign, readwrite) BOOL enableCloseButton;
@property (nonatomic, assign, readwrite, nullable) NSNumber* enableCloseButton;
@property (nonatomic, readwrite) BlueShiftInAppLayoutMargin *margin;
@property (nonatomic, readwrite) BlueShiftInAppNotificationButton *closeButton;
@property (nonatomic, assign, readwrite, nullable) NSNumber *backgroundDimAmount;
Expand Down
Loading

0 comments on commit 377a223

Please sign in to comment.