From 3227aa16dc39b32255c0f1fd8aacf3bcbc46fd26 Mon Sep 17 00:00:00 2001 From: Ketan Shikhare Date: Tue, 15 Jun 2021 12:18:46 +0530 Subject: [PATCH 1/4] created mutable dictionary for adding browser platform Fixed memory leak issue for the html inapp --- BlueShift-iOS-SDK/BlueShift.m | 9 ++- .../BlueShiftInAppNotificationManager.m | 55 ++++++++++++------- ...BlueShiftNotificationModalViewController.m | 2 +- .../BlueShiftNotificationViewController.h | 4 +- .../BlueShiftNotificationWebViewController.h | 2 +- .../BlueShiftNotificationWebViewController.m | 8 +-- 6 files changed, 47 insertions(+), 33 deletions(-) diff --git a/BlueShift-iOS-SDK/BlueShift.m b/BlueShift-iOS-SDK/BlueShift.m index acb86e79..85b47c02 100644 --- a/BlueShift-iOS-SDK/BlueShift.m +++ b/BlueShift-iOS-SDK/BlueShift.m @@ -667,12 +667,11 @@ - (void)performRequestQueue:(NSMutableDictionary *)parameters canBatchThisEvent: if([self validateSDKTrackingRequirements] == false) { return; } - - parameters[kBrowserPlatform] = [BlueShiftDeviceData currentDeviceData].operatingSystem; - - if (parameters != nil) { + NSMutableDictionary* mutableParams = [parameters mutableCopy]; + [mutableParams setValue:[BlueShiftDeviceData currentDeviceData].operatingSystem forKey:kBrowserPlatform]; + if (mutableParams != nil) { 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]; } } diff --git a/BlueShift-iOS-SDK/InApps/BlueShiftInAppNotificationManager.m b/BlueShift-iOS-SDK/InApps/BlueShiftInAppNotificationManager.m index 9c6796b4..90e614e5 100755 --- a/BlueShift-iOS-SDK/InApps/BlueShiftInAppNotificationManager.m +++ b/BlueShift-iOS-SDK/InApps/BlueShiftInAppNotificationManager.m @@ -654,33 +654,32 @@ -(void)processHTMLNotification:(BlueShiftInAppNotification*)notification display [BlueshiftLog logInfo:@"Creating HTML in-app notification to display on screen name" withDetails:displayOnScreen methodName:nil]; BlueShiftNotificationViewController* notificationVC = [[BlueShiftNotificationWebViewController alloc] initWithNotification:notification]; notificationVC.displayOnScreen = displayOnScreen; + notificationVC.delegate = self; self.currentNotificationController = notificationVC; - + BlueShiftNotificationWebViewController *webViewController = (BlueShiftNotificationWebViewController*) notificationVC; - [webViewController setupWebView:^{ - [self presentInAppViewController:notificationVC forNotification:notification]; - }]; + [webViewController setupWebView]; } // Present ViewController - (void)presentInAppViewController:(BlueShiftNotificationViewController*)notificationController forNotification:(BlueShiftInAppNotification*)notification { - if (notificationController && [BlueshiftEventAnalyticsHelper isNotNilAndNotEmpty:notificationController.displayOnScreen]) { - if(self.inAppNotificationDisplayOnPage == nil || ![self.inAppNotificationDisplayOnPage isEqualToString:notificationController.displayOnScreen]) { - self.currentNotificationController = nil; - [BlueshiftLog logInfo:@"Skipping preseting in-app notification as current screen is different than in-app notification display on screen" withDetails:[self inAppNotificationDisplayOnPage] methodName:nil]; - return; - } - } void(^ presentInAppBlock)(void) = ^{ - if (notificationController && [self inAppNotificationDisplayOnPage]) { - [BlueshiftLog logInfo:@"Presenting in-app notification on the screen name" withDetails:[self inAppNotificationDisplayOnPage] methodName:nil]; - notificationController.delegate = self; - notificationController.inAppNotificationDelegate = self.inAppNotificationDelegate; - [notificationController setTouchesPassThroughWindow: notification.templateStyle.enableBackgroundAction]; - [notificationController show:YES]; - } else { - self.currentNotificationController = nil; - [BlueshiftLog logInfo:@"Skipping preseting in-app notification as screen is not registered to receive in-app notification" withDetails:[self inAppNotificationDisplayOnPage] methodName:nil]; + @try { + if (notificationController && [self shouldDisplayInAppNotification:notificationController.displayOnScreen] == YES) { + [BlueshiftLog logInfo:@"Presenting in-app notification on the screen name" withDetails:[self inAppNotificationDisplayOnPage] methodName:nil]; + if(notificationController.delegate == nil) { + notificationController.delegate = self; + } + notificationController.inAppNotificationDelegate = self.inAppNotificationDelegate; + [notificationController setTouchesPassThroughWindow: notification.templateStyle.enableBackgroundAction]; + [notificationController show:YES]; + } else { + self.currentNotificationController = nil; + [BlueshiftLog logInfo:@"Skipped preseting in-app notification as screen is not registered to receive in-app notification or current screen is different than in-app notification display on screen." withDetails:[self inAppNotificationDisplayOnPage] methodName:nil]; + } + + } @catch (NSException *exception) { + [BlueshiftLog logException:exception withDescription:nil methodName:[NSString stringWithUTF8String:__PRETTY_FUNCTION__]]; } }; @@ -693,6 +692,22 @@ - (void)presentInAppViewController:(BlueShiftNotificationViewController*)notific } } + +/// Check if the notification is eligible to display on the current screen. +/// @param displayOnScreen Name of screen where notification should be displayed +- (BOOL)shouldDisplayInAppNotification:(NSString*)displayOnScreen { + if ([self inAppNotificationDisplayOnPage] == nil) { + return false; + } else if ([BlueshiftEventAnalyticsHelper isNotNilAndNotEmpty:displayOnScreen]) { + if(![[self inAppNotificationDisplayOnPage] isEqualToString:displayOnScreen]) { + return false; + } else { + return true; + } + } + return true; +} + #pragma mark - In App events // Notification Click Callbacks -(void)inAppDidDismiss:(NSDictionary *)notificationPayload fromViewController:(BlueShiftNotificationViewController *)controller { diff --git a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationModalViewController.m b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationModalViewController.m index 50978f55..de4d6449 100644 --- a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationModalViewController.m +++ b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationModalViewController.m @@ -473,7 +473,7 @@ - (CGSize)getAutoImageSizeForNotificationView { NSData* imageData = [self loadAndCacheImageForURLString:self.notification.templateStyle.backgroundImage]; UIImage* image = [[UIImage alloc] initWithData:imageData]; - [BlueshiftLog logInfo:@"Downloaded Image size is" withDetails:[NSString stringWithFormat:@"H:%f, W:%f",image.size.height,image.size.width] methodName:nil]; + [BlueshiftLog logInfo:@"Image size is" withDetails:[NSString stringWithFormat:@"H:%f, W:%f",image.size.height,image.size.width] methodName:nil]; // If auto height and auto width is set for image modal // and image resolution is less than the device height and width, use the image dimention. diff --git a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationViewController.h b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationViewController.h index 9df2357f..70a18ed2 100644 --- a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationViewController.h +++ b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationViewController.h @@ -16,9 +16,9 @@ NS_ASSUME_NONNULL_BEGIN @protocol BlueShiftNotificationDelegate @optional - (void)inAppDidDismiss:(NSDictionary *)notificationPayload fromViewController:(BlueShiftNotificationViewController*)controller; -- (void)inAppActionDidTapped:(NSDictionary *)notificationActionButtonPayload fromViewController:(BlueShiftNotificationViewController *) -controller; +- (void)inAppActionDidTapped:(NSDictionary *)notificationActionButtonPayload fromViewController:(BlueShiftNotificationViewController *)controller; - (void)inAppDidShow:(NSDictionary *)notification fromViewController:(BlueShiftNotificationViewController*)controller; +- (void)presentInAppViewController:(BlueShiftNotificationViewController*)notificationController forNotification:(BlueShiftInAppNotification*)notification; @end @interface BlueShiftNotificationViewController : UIViewController diff --git a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.h b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.h index 644c9841..e112fdd7 100644 --- a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.h +++ b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN @interface BlueShiftNotificationWebViewController : BlueShiftNotificationViewController -- (void)setupWebView:(void (^)(void))block; +- (void)setupWebView; @end NS_ASSUME_NONNULL_END diff --git a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.m b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.m index f309cd12..fd85b579 100755 --- a/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.m +++ b/BlueShift-iOS-SDK/InApps/BlueShiftNotificationWebViewController.m @@ -18,7 +18,6 @@ @interface BlueShiftNotificationWebViewController ()didLoadWebView(); + if ([self delegate] && [[self delegate] respondsToSelector:@selector(presentInAppViewController:forNotification:)]) { + [[self delegate] presentInAppViewController:self forNotification:self.notification]; + } [self resizeWebViewAsPerContent:webView]; }); } From 4f131ea650ac97d7acaebd46820ce2ab6102475c Mon Sep 17 00:00:00 2001 From: Ketan Shikhare Date: Tue, 15 Jun 2021 13:27:52 +0530 Subject: [PATCH 2/4] set useinfo attributes as nullable --- BlueShift-iOS-SDK/BlueShiftUserInfo.h | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/BlueShift-iOS-SDK/BlueShiftUserInfo.h b/BlueShift-iOS-SDK/BlueShiftUserInfo.h index 9a8e068b..60642db3 100644 --- a/BlueShift-iOS-SDK/BlueShiftUserInfo.h +++ b/BlueShift-iOS-SDK/BlueShiftUserInfo.h @@ -12,37 +12,37 @@ /// 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. /// Set this flag to true if you want to stop receiving push notifications for that user. -@property NSNumber* unsubscribed; +@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; @@ -50,10 +50,10 @@ /// 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 From d4e7e45435e6c800e0d1e05017c276612aba07cb Mon Sep 17 00:00:00 2001 From: Ketan Shikhare Date: Tue, 15 Jun 2021 13:50:37 +0530 Subject: [PATCH 3/4] Modified silent push category name --- BlueShift-iOS-SDK/BlueShiftNotificationConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h b/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h index 97bfd0ba..b52d68e9 100755 --- a/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h +++ b/BlueShift-iOS-SDK/BlueShiftNotificationConstants.h @@ -33,7 +33,7 @@ #define kNotificationCategoryViewCartIdentifier @"view_cart" #define kNotificationActionOpenCartIdentifier @"open_cart" -#define kNotificationCategorySilentPushIdentifier @"silent_push" +#define kNotificationCategorySilentPushIdentifier @"silent push" #define kNotificationCategoryOfferIdentifier @"promotion" #define kNotificationProductIDIdenfierKey @"product_id" #define kNotificationSelectedIndexKey @"selected_index" From 43664d3b1fd681c541ea874af24799eec92f0584 Mon Sep 17 00:00:00 2001 From: Ketan Shikhare Date: Tue, 15 Jun 2021 14:17:38 +0530 Subject: [PATCH 4/4] Added nil check for parameters attribute --- BlueShift-iOS-SDK/BlueShift.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BlueShift-iOS-SDK/BlueShift.m b/BlueShift-iOS-SDK/BlueShift.m index 85b47c02..b5338668 100644 --- a/BlueShift-iOS-SDK/BlueShift.m +++ b/BlueShift-iOS-SDK/BlueShift.m @@ -667,9 +667,9 @@ - (void)performRequestQueue:(NSMutableDictionary *)parameters canBatchThisEvent: if([self validateSDKTrackingRequirements] == false) { return; } - NSMutableDictionary* mutableParams = [parameters mutableCopy]; - [mutableParams setValue:[BlueShiftDeviceData currentDeviceData].operatingSystem forKey:kBrowserPlatform]; - if (mutableParams != nil) { + 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:[mutableParams copy] andRetryAttemptsCount:kRequestTryMaximumLimit andNextRetryTimeStamp:0 andIsBatchEvent:isBatchEvent]; [BlueShiftRequestQueue addRequestOperation:requestOperation];