2014-04-25 88 views
1

Print from console. Execute: ECB and Stopped at registering appPushPlugin不登記設備和onNotificationGCM

我與PhoneGap的3.4安裝PushPlugin返回REGID。

onNotificationGCM案例:registered從未執行,我無法將regid存儲在我的服務器數據庫中並開始發送通知。

每當我的應用程序打開時,它顯示

  • deviceready活動得到
  • 註冊Android
  • 成功OK

我做:

  • 改變senderid
  • 谷歌雲端通訊Android的 - 開
  • 創建服務器密鑰(但因爲我不是在發送部分不應該是很重要的)

我需要:

  • 安裝谷歌播放服務api?
  • 我錯過了什麼?

我等了幾分鐘,但沒有像

$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>"); 

回答

1

我也有問題,你沒有註冊的消息。刪除包含html的代碼行。如果您想檢索它,請將其存儲到sessionStorage/localStorage,控制檯或提醒它。

我的HTML版本刪除

var pushNotification; 

document.addEventListener("deviceready", onDeviceReady, false); 
// device APIs are available 
// 

function onDeviceReady() { 
    pushNotification = window.plugins.pushNotification; 
    if (device.platform == 'android' || device.platform == 'Android') { 
     console.log("registering android"); 
     window.plugins.pushNotification.register(successHandler, errorHandler, { 
      "senderID": "xxxxxxxxxxx", 
      "ecb": "onNotificationGCM" 
     }); // required! 
    } else { 
     console.log("registering iOS"); 
     pushNotification.register(tokenHandler, errorHandler, { 
      "badge": "true", 
      "sound": "true", 
      "alert": "true", 
      "ecb": "onNotificationAPN" 
     }); // required! 
    } 
} 

// handle APNS notifications for iOS 

function onNotificationAPN(e) { 
    if (e.alert) { 
     navigator.notification.alert(e.alert); 
    } 
    if (e.sound) { 
     var snd = new Media(e.sound); 
     snd.play(); 
    } 
    if (e.badge) { 
     pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge); 
    } 
} 
// handle GCM notifications for Android 

function onNotificationGCM(e) { 
    navigator.notification.alert(e.event); 
    switch (e.event) { 
    case 'registered': 
     if (e.regid.length > 0) { 
      navigator.notification.alert(e.regid); 
      // Your GCM push server needs to know the regID before it can push to this device 
      // here is where you might want to send it the regID for later use. 
      console.log("regID = " + e.regid); 
      sessionStorage.setItem("deviceId",e.regid); 
     } 
     break; 
    case 'message': 
     // if this flag is set, this notification happened while we were in the foreground. 
     // you might want to play a sound to get the user's attention, throw up a dialog, etc. 
     if (e.foreground) { 
      navigator.notification.alert('--INLINE NOTIFICATION--'); 
      // if the notification contains a soundname, play it. 
      var my_media = new Media("/android_asset/www/" + e.soundname); 
      my_media.play(); 
     } else { // otherwise we were launched because the user touched a notification in the notification tray. 
      if (e.coldstart) navigator.notification.alert('--COLDSTART NOTIFICATION--'); 
      else navigator.notification.alert('--BACKGROUND NOTIFICATION--'); 
     } 
     navigator.notification.alert(e.payload.message); 
     navigator.notification.alert('MESSAGE -> MSGCNT: ' + e.payload.msgcnt); 
     break; 
    case 'error': 
     navigator.notification.alert('ERROR -> MSG:' + e.msg); 
     break; 
    default: 
     navigator.notification.alert('EVENT -> Unknown, an event was received and we do not know what it is'); 
     break; 
    } 
} 

function tokenHandler(result) { 
    navigator.notification.alert(result, null, 'Alert', 'OK'); 
    sessionStorage.setItem("deviceId", result); 
    sessionStorage.setItem("notificationServer", "APNS"); 
    // Your iOS push server needs to know the token before it can push to this device 
    // here is where you might want to send it the token for later use. 
} 

function successHandler(result) { 
    navigator.notification.alert(result, null, 'Alert', 'OK'); 
    sessionStorage.setItem("deviceId", result); 
    sessionStorage.setItem("notificationServer", "GCM"); 
} 

function errorHandler(error) { 
    navigator.notification.alert(error, null, 'Alert', 'OK'); 
} 
+0

我已經使用你的代碼。 onNotificationGCM註冊從未被調用過。 – Fxster

+0

確保您首先將對話框和控制檯phongap插件安裝到您的項目中。 –

+0

這些都是我安裝的插件:E:\ androidworkspace \ PG>的PhoneGap本地插件列表 [PhoneGap的] com.phonegap.plugins.PushPlugin [PhoneGap的] org.apache.cordova.console [PhoneGap的] org.apache.cordova設備 [phonegap] org.apache.cordova.dialogs [phonegap] org.apache.cordova.splashscreen [phonegap] org.apache.cordova。振動 – Fxster

0

解決。經過這麼多天的搜索,pushplugin或phonegap沒什麼問題。這一輪,這是電話本身。許多人在android 4.2.2上面臨推送通知問題,尤其是s4。它也不適用於我的Android 4.2.2平板電腦。我不知道whatsapp和facebook是如何做到的,在任何地方它們都是真正的原生應用程序,所以我相信他們對調試有更多的控制。

我如何解決...首先,我做了一個工廠重置並安裝相同的應用程序..它的工作原理沒有任何代碼的變化!繼續前進,我擔心4.2.2的問題會回來,我已升級到固件4.3,現在它工作得很好。