Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegisterAPN error callback never registered/called #7

Closed
jonathantrevor opened this issue Dec 20, 2011 · 1 comment
Closed

RegisterAPN error callback never registered/called #7

jonathantrevor opened this issue Dec 20, 2011 · 1 comment

Comments

@jonathantrevor
Copy link

Im not getting the error callback called when a register failure occurs:

if (argc > 1 && [[arguments objectAtIndex:1] length] > 0) {
    NSLog(@"registererror");
    self.registerErrorCallback = [arguments objectAtIndex:1];
}

The logging statement never gets called, so I assume there's some issue with passing the js callback through.

Here's the register call from the JS side:

    window.plugins.pushNotification.register(
        successAPNCallback,
        errorAPNCallback,
        [ {
         alert:true,
         badge:true,
         sound:true
        }]
    );

Success callback works just fine.

@jonathantrevor
Copy link
Author

Finally worked it out. The git code seems to span 2 types of callback system in Phonegap and doesn't work perfectly with either.

The argc line is an old-style (I think/hope) way of registering callbacks in Phonegap, as the callbackId scheme contains BOTH the success AND the failure callback references.

Therefore to call the error callback when an error occurs we need to find the error handler and invoke it:

  • (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"didFailToRegisterForRemoteNotificationsWithError:%@", error);

    NSMutableDictionary results = [NSMutableDictionary dictionary];
    PluginResult
    pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsDictionary:results];
    [self writeJavascript:[pluginResult toErrorCallbackString:self.callbackId]];

Not sure how to plug the error into the result dictionary but that isnt critical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant