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

iOS only receives first notification in foreground #42

Closed
ashconnell opened this issue Jul 15, 2015 · 2 comments
Closed

iOS only receives first notification in foreground #42

ashconnell opened this issue Jul 15, 2015 · 2 comments

Comments

@ashconnell
Copy link
Contributor

Sending a push notification only calls on('notification') once, while the app is in the foreground.

To reproduce:

  • add a console.log to the on('notification') callback
  • deploy to device and leave the app in the foreground
  • send it a push notification
  • XCode logs native Push Plugin key: alert etc
  • on('notification') callback is fired and outputs to log
  • send another push notification
  • xcode still logs native Push Plugin key: alert etc
  • on('notification') doesn't get fired
@ashconnell
Copy link
Contributor Author

Figured it out. The reason this happens is because the new setApplicationBadgeNumber functionality overwrites the callbackId used for the .on() methods.

I'll make a pull request for this and #41 soon but for those who need it here's what i did.

  1. I changed the javascript prototype method for setApplicationBadgeNumber to use exec() instead of cordova.exec() as it's already required in the file.
exec(successCallback, errorCallback, "PushNotification", "setApplicationIconBadgeNumber", [{badge: badge}]);
  1. I changed -(void)setApplicationIconBadgeNumber... to use his own callbackId instead of overwriting the .on() pipe callbackId

OLD:

- (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {

    self.callbackId = command.callbackId;

    NSMutableDictionary* options = [command.arguments objectAtIndex:0];
    int badge = [[options objectForKey:@"badge"] intValue] ?: 0;

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];

    [self successWithMessage:[NSString stringWithFormat:@"app badge count set to %d", badge]];
}

NEW:

- (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command 
{
    NSMutableDictionary* options = [command.arguments objectAtIndex:0];
    int badge = [[options objectForKey:@"badge"] intValue] ?: 0;

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];

    NSString* message = [NSString stringWithFormat:@"app badge count set to %d", badge];
    CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
    [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
}

ashconnell pushed a commit to ashconnell/phonegap-plugin-push that referenced this issue Jul 15, 2015
macdonst added a commit that referenced this issue Jul 17, 2015
@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants