2013-11-27 13 views
1

我正嘗試在Android Phone Gap應用程序中實現Urban Airship。我正在使用github上的Urban Airship Phone Gap插件。我知道城市飛艇成功註冊該設備,因爲:如何使用Urban Airship插件獲取手機間隙Android應用程序中的APID

  1. 它告訴我的logcat
  2. 該設備顯示在我的城市飛艇的設備,我能推到它

我還可以掛接到urbanairship.push事件,像這樣:

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

出於某種原因,但是,urbanairship.registration事件不會開火。這裏是我的代碼:

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) 
     } 
    } 

我需要這個啓動,所以我可以將設備的APID保存在我的後端。這兩個都在我的onDeviceReady回調中。

回答

0

看來這個插件與Cordova 3.0.0不是很兼容。我升級到Cordova 3.1.0(cordova-3.1.0.jar),並將我的Urban Airship應用程序更改爲生產版本,而不是開發版本,並且工作正常。

+0

嘿,我發現了一個辦法讓通過UA的JS API的APID。它適用於我的開發和生產。 – Ross

0

我查看了UA的PhoneGap Push插件的源代碼,它有一個可以檢索您的APID的函數。

使用此之下deviceready後已經解僱中檢索您的APID -

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

我知道這肯定能幫助任何人在未來尋求了這一點。這對我來說非常適合Android,我很快就會在iOS上進行測試。

您可以通過根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" /> 
相關問題