這個問題很長並涉及到,但我希望有人能幫我一把。我正在編寫需要發送和接收推送通知的Phonegap應用程序。我想爲此使用Azure服務總線,以便我可以部署到多個移動平臺。現在我只是測試Android。我設置了我的Google和Azure帳戶,並且其代碼正常工作。當我在我的設備上部署我的應用時,onGcmNotification被解僱,我從google獲得regid。然後我註冊了提供的regid和模板,之後我得到了一個提醒(「註冊了Hub!」),所以我認爲一切正常。但是,當通過Azure調試控制檯進行測試時,我無法獲得任何推送通知。見下圖。它只是一直告訴我「未找到所選平臺的註冊」。我的已部署應用程序中沒有彈出任何內容,onGcmNotification永遠不會被觸發。我錯過了什麼?是否有另一種方法來完成我正在嘗試的目標?Windows Azure服務總線和GCM推送通知
var GCM_SENDER_ID = 'XXXXXXXXXXXXX';
var MOBILE_SERVICE_URL = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var MOBILE_SERVICE_APP_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var mobileServiceClient;
var pushNotification;
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, true);
},
onDeviceReady: function() {
angular.element(document).ready(function() {
mobileServiceClient = new WindowsAzure.MobileServiceClient(MOBILE_SERVICE_URL, MOBILE_SERVICE_APP_KEY);
// Create a pushNotification (from the PushPlugin).
pushNotification = window.plugins.pushNotification;
// Platform-specific registrations.
if (device.platform == 'android' || device.platform == 'Android') {
// Register with GCM for Android apps.
pushNotification.register(successHandler, errorHandler,
{
"senderID": GCM_SENDER_ID,
"ecb": "onGcmNotification"
});
} else if (device.platform === 'iOS') {
// Register with APNS for iOS apps.
pushNotification.register(tokenHandler, errorHandler,
{
"badge": "false",
"sound": "false",
"alert": "true",
"ecb": "onApnsNotification"
});
}
angular.bootstrap(document, ['app']);
});
},
};
// Handle a GCM notification.
function onGcmNotification(e) {
switch (e.event) {
case 'registered':
// Handle the registration.
if (e.regid.length > 0) {
console.log("gcm id " + e.regid);
if (mobileServiceClient) {
// Create the integrated Notification Hub client.
var hub = new NotificationHub(mobileServiceClient);
// Template registration.
var template = "{ \"data\" : {\"message\":\"$(message)\"}}";
// Register for notifications.
// (gcmRegId, ["tag1","tag2"], templateName, templateBody)
hub.gcm.register(e.regid, null, "myTemplate", template).done(function() {
alert("Registered with hub!");
}).fail(function (error) {
alert("Failed registering with hub: " + error);
});
}
}
break;
case 'message':
console.log("received message: " + e.message);
if (e.foreground) {
alert(e.payload.message);
}
break;
case 'error':
alert('GCM error: ' + e.message);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
此博客文章可能有所幫助:http://blogs.msdn.com/b/azuremobile/archive/2014/06/17/push-notifications-to-phonegap-apps-using-notification-hubs-integration.aspx – 2015-02-18 07:51:35
我正在經歷相同的結果。你有沒有得到任何結果? – ChepA 2015-07-01 14:45:02