2013-10-14 217 views
3

我有一個非常奇怪的問題,現在已經讓我瘋狂了一天。我有一個Phonegap Build 3.0應用程序,並試圖集成Push plugin。問題是,即使我遵循文檔和很多很多的例子,dang的東西就不會工作。我無法讓它解決成功或錯誤回調,try/catch報告沒有問題。Phonegap Build推送通知插件問題

頭:

<head> 
    <script src="assets/js/myScripts.js"></script> 
    <script src="phonegap.js"></script> 
    <script type="text/javascript" src="PushNotification.js"></script> 
</head> 

myScripts.js

var myPushNotification; 
document.addEventListener("deviceready", onDeviceReady, false); 

function onDeviceReady(){ 
    myPushNotification = window.plugins.pushNotification; 
    try{ 
     myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"}); 
    } 
    catch(e){ 
     alert(e.message);//******this is never fired****** 
    } 
} 

function gcmRegistrationSuccessHandler(result){ 
    alert("successfully registered);//******this is never fired****** 
} 

function gcmRegistrationErrorHandler(error){ 
    alert("error registering");//******this is never fired****** 
} 

config.xml中包含:

<access origin="*"/> 

<gap:platform name="android" /> 
<gap:platform name="ios" /> 

<gap:plugin name="com.phonegap.plugins.pushplugin" /> 

任何幫助將不勝感激。

+0

更新:我在Phonegap Build的調試模式下運行了這個,並試圖直接調用myPushNotification.register(gcmRegistrationSuccessHandler,gcmRegistrationErrorHandler,{「senderID」:「我在這裏有我的發件人ID」,「 ecb「:」onNotificationGCM「});'並且日誌顯示它返回爲未定義的地方,因爲調用'myPushNotification = window.plugins.pushNotification;'返回它應該的對象。 – Dom

回答

1

問題已解決。事實證明,myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"});中的「gcmRegistrationSuccessHandler」回調從未被調用過。只有「onNotificationGCM」被調用,你必須採取所有的行動。當然希望有記錄...

+0

我堅持你有Dom的確切問題,仍然無法修復它,我嘗試匿名函數,以及我的應用程序內的回調函數仍然沒有運氣,我仍然不明白你是如何得到它的工作?這是我的線程http://stackoverflow.com/questions/22350971/phonegap-build-push-notification-android – pleshy