Skip to content

Commit

Permalink
add tapped (bool) property on additionData on iOS;
Browse files Browse the repository at this point in the history
  • Loading branch information
menelike committed Nov 12, 2016
1 parent 9e9df7c commit 5b54836
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
57 changes: 26 additions & 31 deletions src/ios/AppDelegate+notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ - (void) application:(UIApplication *)application didReceiveRemoteNotification:(
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
pushHandler.notificationMessage = userInfo;
pushHandler.isInline = NO;
pushHandler.tapped = true;
[pushHandler notificationReceived];
}

Expand All @@ -113,6 +114,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
pushHandler.notificationMessage = userInfo;
pushHandler.isInline = YES;
pushHandler.tapped = false;
[pushHandler notificationReceived];

completionHandler(UIBackgroundFetchResultNewData);
Expand All @@ -131,39 +133,32 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
silent = [contentAvailable integerValue];
}

if (silent == 1) {
NSLog(@"this should be a silent push");
void (^safeHandler)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result){
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(result);
});
};

PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];

if (pushHandler.handlerObj == nil) {
pushHandler.handlerObj = [NSMutableDictionary dictionaryWithCapacity:2];
}

id notId = [userInfo objectForKey:@"notId"];
if (notId != nil) {
NSLog(@"Push Plugin notId %@", notId);
[pushHandler.handlerObj setObject:safeHandler forKey:notId];
} else {
NSLog(@"Push Plugin notId handler");
[pushHandler.handlerObj setObject:safeHandler forKey:@"handler"];
}

pushHandler.notificationMessage = userInfo;
pushHandler.isInline = NO;
[pushHandler notificationReceived];
} else {
NSLog(@"just put it in the shade");
//save it for later
self.launchNotification = userInfo;
void (^safeHandler)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result){
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(result);
});
};

PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];

completionHandler(UIBackgroundFetchResultNewData);
if (pushHandler.handlerObj == nil) {
pushHandler.handlerObj = [NSMutableDictionary dictionaryWithCapacity:2];
}

id notId = [userInfo objectForKey:@"notId"];
if (notId != nil) {
NSLog(@"Push Plugin notId %@", notId);
[pushHandler.handlerObj setObject:safeHandler forKey:notId];
} else {
NSLog(@"Push Plugin notId handler");
[pushHandler.handlerObj setObject:safeHandler forKey:@"handler"];
}

pushHandler.notificationMessage = userInfo;
pushHandler.isInline = NO;
pushHandler.tapped = true;
[pushHandler notificationReceived];
completionHandler(UIBackgroundFetchResultNewData);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
{
NSDictionary *notificationMessage;
BOOL isInline;
BOOL tapped;
NSString *notificationCallbackId;
NSString *callback;
BOOL clearBadge;
Expand All @@ -50,6 +51,7 @@
@property (nonatomic, strong) NSDictionary *notificationMessage;
@property BOOL isInline;
@property BOOL coldstart;
@property BOOL tapped;
@property BOOL clearBadge;
@property (nonatomic, strong) NSMutableDictionary *handlerObj;

Expand Down
8 changes: 8 additions & 0 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @implementation PushPlugin : CDVPlugin
@synthesize notificationMessage;
@synthesize isInline;
@synthesize coldstart;
@synthesize tapped;

@synthesize callbackId;
@synthesize notificationCallbackId;
Expand Down Expand Up @@ -554,6 +555,12 @@ - (void)notificationReceived {
[additionalData setObject:[NSNumber numberWithBool:NO] forKey:@"coldstart"];
}

if (tapped) {
[additionalData setObject:[NSNumber numberWithBool:YES] forKey:@"tapped"];
} else {
[additionalData setObject:[NSNumber numberWithBool:NO] forKey:@"tapped"];
}

[message setObject:additionalData forKey:@"additionalData"];

// send notification message
Expand All @@ -563,6 +570,7 @@ - (void)notificationReceived {

self.coldstart = NO;
self.notificationMessage = nil;
self.tapped = false;
}
}

Expand Down

0 comments on commit 5b54836

Please sign in to comment.