这个问题很长并涉及到,但我希望有人能帮我一把。我正在编写需要发送和接收推送通知的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