如何使用phonegap/cordova访问随城市航空推送请求发送的额外数据

如何使用phonegap/cordova访问随城市航空推送请求发送的额外数据,cordova,push-notification,urbanairship.com,Cordova,Push Notification,Urbanairship.com,如何使用phonegap/cordova访问随城市航空推送请求发送的额外数据?这仅适用于android 服务器发送的推送通知的数据 { "audience": "all", "notification": { "alert": "Extras example", "android": { "extra": { "url": "http://example.com", "story_id": "12

如何使用phonegap/cordova访问随城市航空推送请求发送的额外数据?

这仅适用于android

服务器发送的推送通知的数据

{
   "audience": "all",
   "notification": {
      "alert": "Extras example",
      "android": {
        "extra": {
            "url": "http://example.com",
            "story_id": "1234",
            "moar": "{\"key\": \"value\"}"
         }
      }
   },
   "device_types": ["android"]
}
访问发送的额外数据。您需要访问
事件.extras
参数。是,数据作为
事件.extra
发送,但您需要使用
事件.extras
访问它

例如:

//if you have a handleIncomingPush callback registered with 
//the urbanairship.push event listener

var pushUrl;//global variable to store the url

document.addEventListener("urbanairship.push", handleIncomingPush, false);

 var handleIncomingPush = function(event) {

      if(event.extras.url)
      { 
       pushUrl  = event.extras.url);//you can use this url elsewhere 
       alert(pushUrl);//this will output http://example.com
      }
      if(event.message) {
        console.log("Incoming push: " + event.message);

      } else {
        console.log("No incoming message");
      }
    };