Question

I am trying to implement Urban Airship in an Android Phone Gap application. I am using the Urban Airship Phone Gap plugin found on github. I know Urban Airship is successfully registering the device because:

  1. It is telling me in LogCat
  2. The device is showing up in my Urban Airship devices and I am able to push to it

I am also able to hook into the urbanairship.push event like so:

document.addEventListener("urbanairship.push", handleIncomingPush, false)
function handleIncomingPush(event) {
      if(event.message) {
        console.log("Incoming push: " + event.message)
      } else {
        console.log("No incoming message")
      }
    }

For some reason, however, the urbanairship.registration event is not firing. Here is my code:

document.addEventListener("urbanairship.registration", onRegistration, false)
function onRegistration(event)  {
      if (!event.error) {
        console.log("Reg Success: " + event.pushID)
      } else {
        console.log('push registration error: ' + event.error)
      }
    }

I need this to fire so I can save the device's APID on my backend. Both of these are inside my onDeviceReady callback.

Was it helpful?

Solution

It appears the plugin is not very compatible with Cordova 3.0.0. I upgraded to Cordova 3.1.0 (cordova-3.1.0.jar) and changed my Urban Airship app to production instead of development and it worked.

OTHER TIPS

I looked at UA's source code for their PhoneGap Push plugin and it has a function that can retrieve your APID.

Use this below after deviceready has fired to retreive your APID -

PushNotification.enablePush(function() {
    console.log('push has been enabled');
    PushNotification.getPushID(function(apid) {
        console.log('got push apid, apid: ' + apid);
    });
});

I know this can certainly help anyone seeking this out in the future. This is working great for me on Android, I'll soon be testing on iOS.

You can enable push automatically on app launch like this via the root config.xml -

<!-- Enable push when the application launches (instead of waiting for enablePush js call).  Defaults to false -->
<preference name="com.urbanairship.enable_push_onlaunch" value="true | false" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top