1

I'm a newbie phonegap developer but I have several years developing with objective-C.

I'm trying to execute code in JS (phonegap) from a remote notification in iOS. I have working for several days with https://github.com/phonegap-build/PushPlugin

What I could achieve is to:

  • Get Device token
  • execute code in JS when the app is in foreground

Not achieved :

  • execute code in JS when the app is in background
  • execute code in JS when the app is stopped.

After a close analysis of the plugin I figured out that the plugin save the notification and launches them when the app is in foreground.

Next I tried to modify the plugin to be able to execute my js code. What I did, It was to comment these lines.

<!-- language: objective-c -->
//if (application.applicationState == UIApplicationStateActive) {
    PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"];
    pushHandler.notificationMessage = userInfo;
    pushHandler.isInline = YES;
    [pushHandler notificationReceived];
//} else {
    //save it for later
    self.launchNotification = userInfo;
//}

I didn't succeed and I couldn't find out why the webview is not loaded and the code isn't executed. Is it possible to execute like this? Or I will have to tho a new plugin and execute the code in objective-c?

Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50
Jpicerno
  • 21
  • 3
  • I am not sure how this can be done on iOS. But here is my [answer](http://stackoverflow.com/a/29437083/1761793) on how to solve a related problem in Android (if it helps in any way). To solve this problem in android, PushPlugin can be customized [here](https://github.com/phonegap-build/PushPlugin/blob/master/src/android/com/plugin/gcm/GCMIntentService.java#L59) to run a JS function according to your needs. – Ajoy May 27 '15 at 03:13

0 Answers0