0

根据 PushWhoosh 的文档:

http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/

我应该能够使用 Adob​​e 的 Build 云服务来构建 PhoneGap 应用程序。我已按照文档中的说明进行操作,但无法让我的应用注册 PushWhoosh 服务(即:它不发送设备令牌)。

我认为这个问题与在config.xml. 根据 Adob​​e Build docs,唯一支持的推送插件是他们的“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 控制面板中显示为注册设备。

有任何想法吗?

4

3 回答 3

3

你确定这段代码是正确的吗?

pushNotification.register(successHandler, errorHandler, { "senderID": " replace_with_sender_id ", "ecb": "onNotificationGCM" });

不应该是 GCM 的项目 ID 吗?它可能解释了为什么设备不注册推送通知。

于 2013-05-31T13:03:16.890 回答
1

我不熟悉 PushWoosh,但他们确实有关于如何通过 Build 实现此目的的指南: http ://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/

您是否遵循了每一步?

于 2013-05-30T22:25:32.543 回答
0

如果你还没有成功(我希望你有)试试这个指南:

http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

我现在自己使用推送通知构建了一个解决方案,发现我最大的问题是我没有设置证书。这个指南很完美。

还请记住,推送通知在模拟器中不起作用,只能在真实设备上使用。

于 2013-08-24T08:44:59.217 回答