Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
[SDK-637] : iOS push notification callback changes implemented (#90)
Browse files Browse the repository at this point in the history
* iOS push notification callback improve logs and checks added to handle the push sent from Countly only.

* Implemented requested changes of PR

* Update CountlyNative.m

Logs positions changes in onNotification function.

* Deleting unneeded logs

Co-authored-by: ArtursKadikis <[email protected]>
  • Loading branch information
ijunaid and ArtursKadikis authored Jan 20, 2022
1 parent 90d8c07 commit f6416fb
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/ios/CountlyNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,36 @@ @implementation CountlyNative
Boolean isDebug = false;

+ (void)onNotification: (NSDictionary *) notificationMessage{
COUNTLY_CORDOVA_LOG(@"Notification received");
COUNTLY_CORDOVA_LOG(@"The notification %@", notificationMessage);
if(notificationMessage && notificationListener != nil){
notificationListener([NSString stringWithFormat:@"%@",notificationMessage]);
}else{
lastStoredNotification = notificationMessage;
if(!notificationMessage) {
COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. No valid message");
return;
}
if(notificationMessage){
if(notificationIDs == nil){
notificationIDs = [[NSMutableArray alloc] init];
COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. The notification %@", notificationMessage);

NSDictionary* countlyPayload = notificationMessage[@"c"];
if(!countlyPayload) {
COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. Countly payload not found in notification dictionary!");
return;
}
NSString *notificationID = countlyPayload[@"i"];
if(!notificationID) {
COUNTLY_CORDOVA_LOG(@"onNotification, Notification received. Countly payload does not contains a valid notification ID!");
return;
}

if(notificationIDs == nil){
notificationIDs = [[NSMutableArray alloc] init];
}
[notificationIDs insertObject:notificationID atIndex:[notificationIDs count]];
if(isInitialized){
if(notificationListener != nil){
notificationListener([NSString stringWithFormat:@"%@",notificationMessage]);
}
NSDictionary* countlyPayload = notificationMessage[@"c"];
NSString *notificationID = countlyPayload[@"i"];
[notificationIDs insertObject:notificationID atIndex:[notificationIDs count]];
[self recordPushAction];
}
else{
// Notification is cached if SDK is not initialized and send in callback when 'registerForNotification' is call.
lastStoredNotification = notificationMessage;
}
}
- (void)recordPushAction
Expand All @@ -251,7 +267,7 @@ - (void)recordPushAction
};
[Countly.sharedInstance recordEvent:@"[CLY]_push_action" segmentation: segmentation];
}
notificationIDs = nil;
[notificationIDs removeAllObjects];
}

- (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Result) result{
Expand Down

0 comments on commit f6416fb

Please sign in to comment.