根据PushWhoosh上的文档:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
我应该能够使用Adobe的Build云服务来构建PhoneGap应用程序。我已按照文档中的说明进行操作,但无法让我的应用向PushWhoosh服务注册(即:它没有发送设备令牌)。
我认为问题与config.xml
中插件的注册有关。根据Adobe Build文档,唯一受支持的推插件是它们的“ GenericPush”,我已将其添加到我的config.xml
文件中,如下所示:
我也将pushwhoosh.com域列入了白名单。
在我的index.html文件中,我具有函数initPushwhoosh,该函数在设备准备就绪时被调用:
function initPushwoosh() {
try {
var pushNotification;
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
}
else {
pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });
}
}
catch (err) {
alert(err.message + "\n\n" + err.name);
}
}
我的tokenHandler函数(我正在为iOS构建)如下所示:
function tokenHandler(result) {
// 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.
PushWoosh.appCode = "E0313-D27FA";
PushWoosh.register(result, function (data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function (errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
通过调试,似乎永远不会调用“ pushNotification.register”函数,并且try / catch语句不会显示任何错误消息。该函数是:
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
PushNotification.prototype.register = function (successCallback, errorCallback, options) {
alert("about to register");
if (errorCallback == null) { errorCallback = function () { } }
if (typeof errorCallback != "function") {
alert("PushNotification.register failure: failure parameter not a function");
return;
}
if (typeof successCallback != "function") {
alert("PushNotification.register failure: success callback parameter must be a function");
return;
}
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
};
我的想法是,它与
<gap:plugin name="GenericPush" />
中的插件声明(config.xml
)有关;我尝试将其更改为(基于我发现的其他一些示例代码):<gap:plugin name="PushPlugin"/>
但这也不起作用。注意:执行此操作时,我尝试更改:
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
至
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
完整的代码可以在这里找到:
https://github.com/appburnr/PushWhooshTest
我对我的PushWhoosh AppID进行了三重检查,但我始终无法使该应用程序在PushWhoosh控制面板中显示为注册设备。
有任何想法吗?
最佳答案
您确定此代码正确吗?
pushNotification.register(successHandler,errorHandler,{“ senderID”:“ replace_with_sender_id”,“ ecb”:“ onNotificationGCM”});
难道不是GCM的专案ID吗?它可以解释为什么设备不注册推送通知。