【发布时间】:2013-05-30 19:12:36
【问题描述】:
根据 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]);
};
我的想法是它与config.xml 中的插件声明(<gap:plugin name="GenericPush" />)有关;我尝试将其更改为(基于我发现的其他一些示例代码):
<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 控制面板中显示为注册设备。
有什么想法吗?
【问题讨论】:
标签: ios push-notification cordova token