Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CleverPush/Source/CPUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
+ (void)tryOpenURL:(NSURL *)url;
+ (BOOL)isValidURL:(NSURL *)url;
+ (NSURL *)removeQueryParametersFromURL:(NSURL *)url;
+ (NSString *)getQueryParameterFromURL:(NSURL *)url forKey:(NSString *)key;
+ (NSDictionary *)convertConnectionOptionsToLaunchOptions:(UISceneConnectionOptions* )connectionOptions API_AVAILABLE(ios(13.0));
+ (UIImage *)resizedImageNamed:(NSString *)imageName withSize:(CGSize)newSize;

Expand Down
19 changes: 19 additions & 0 deletions CleverPush/Source/CPUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,25 @@ + (NSURL *)removeQueryParametersFromURL:(NSURL *)url {
return components.URL;
}

+ (NSString *)getQueryParameterFromURL:(NSURL *)url forKey:(NSString *)key {
if (!url || !key) {
return nil;
}

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
if (!components || !components.queryItems) {
return nil;
}

for (NSURLQueryItem *queryItem in components.queryItems) {
if ([queryItem.name isEqualToString:key]) {
return queryItem.value;
}
}

return nil;
}

#pragma mark - Converts UISceneConnectionOptions to launch options.
+ (NSDictionary *)convertConnectionOptionsToLaunchOptions:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)) {
NSMutableDictionary *launchOptions = [NSMutableDictionary dictionary];
Expand Down
29 changes: 29 additions & 0 deletions CleverPush/Source/CleverPushInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,25 @@ - (void)handleNotificationOpened:(NSDictionary* _Nullable)payload isActive:(BOOL
}
}

NSString *notificationDeeplinkId = nil;
NSString *notificationUrl = [notification objectForKey:@"url"];

if (notificationUrl != nil && ![notificationUrl isKindOfClass:[NSNull class]] && [notificationUrl length] > 0) {
NSURL *notificationURL = [NSURL URLWithString:notificationUrl];
if (notificationURL) {
notificationDeeplinkId = [CPUtils getQueryParameterFromURL:notificationURL forKey:@"deeplinkId"];
}
}

if (notificationDeeplinkId && ![CPUtils isNullOrEmpty:notificationDeeplinkId]) {
[userDefaults setObject:notificationDeeplinkId forKey:CLEVERPUSH_LAST_DEEPLINK_ID_KEY];
[userDefaults setObject:[NSDate date] forKey:CLEVERPUSH_LAST_DEEPLINK_TIME_KEY];
} else {
[userDefaults removeObjectForKey:CLEVERPUSH_LAST_DEEPLINK_ID_KEY];
[userDefaults removeObjectForKey:CLEVERPUSH_LAST_DEEPLINK_TIME_KEY];
}
[userDefaults synchronize];

BOOL hasValidUrl = notification != nil &&
[notification objectForKey:@"url"] != nil &&
![[notification objectForKey:@"url"] isKindOfClass:[NSNull class]] &&
Expand Down Expand Up @@ -3411,6 +3430,16 @@ - (void)trackEvent:(NSString* _Nullable)eventName properties:(NSDictionary* _Nul
[dataDic setObject:lastClickedNotificationId forKey:@"notificationId"];
}
}

NSString* lastDeeplinkId = [userDefaults stringForKey:CLEVERPUSH_LAST_DEEPLINK_ID_KEY];
NSDate* lastDeeplinkTimeStamp = [userDefaults objectForKey:CLEVERPUSH_LAST_DEEPLINK_TIME_KEY];

if (![CPUtils isNullOrEmpty:lastDeeplinkId] && lastDeeplinkTimeStamp != nil && [lastDeeplinkTimeStamp isKindOfClass:[NSDate class]]) {
NSTimeInterval secondsSinceLastDeeplinkClick = [[NSDate date] timeIntervalSinceDate:lastDeeplinkTimeStamp];
if (secondsSinceLastDeeplinkClick <= 60 * 60) {
[dataDic setObject:lastDeeplinkId forKey:@"deeplinkId"];
}
}
Comment thread
cpandya25 marked this conversation as resolved.

NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
[request setHTTPBody:postData];
Expand Down
2 changes: 2 additions & 0 deletions CleverPush/Source/CleverPushUserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define CLEVERPUSH_LAST_NOTIFICATION_ID_KEY @"CleverPush_LAST_NOTIFICATION_ID"
#define CLEVERPUSH_LAST_CLICKED_NOTIFICATION_ID_KEY @"CleverPush_LAST_CLICKED_NOTIFICATION_ID"
#define CLEVERPUSH_LAST_CLICKED_NOTIFICATION_TIME_KEY @"CleverPush_LAST_CLICKED_NOTIFICATION_TIME"
#define CLEVERPUSH_LAST_DEEPLINK_ID_KEY @"CleverPush_LAST_DEEPLINK_ID"
#define CLEVERPUSH_LAST_DEEPLINK_TIME_KEY @"CleverPush_LAST_DEEPLINK_TIME"
#define CLEVERPUSH_NOTIFICATION_CATEGORIES_KEY @"CleverPush_NOTIFICATION_CATEGORIES"

#define CLEVERPUSH_CHANNEL_ID_KEY @"CleverPush_CHANNEL_ID"
Expand Down