【问题标题】:Adobe PhoneGap Build (iOS) and PushWooshAdobe PhoneGap Build (iOS) 和 PushWoosh
【发布时间】:2013-05-30 19:12:36
【问题描述】:

根据 PushWhoosh 的文档:

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

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

我认为问题与在config.xml 中注册插件有关。根据 Adob​​e 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


    【解决方案1】:

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

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

    不应该是 GCM 的项目 ID 吗?这或许可以解释为什么设备不注册推送通知。

    【讨论】:

    • 该代码 sn-p 用于在 Android 上注册推送通知;当我在 iOS 设备上进行测试时,代码 sn-p 永远不会被执行。
    • 问题可能出在您的移动配置文件中。它里面有“aps-environment”字符串吗?如果是这样 - 它说明了什么?
    【解决方案2】:

    我对 PushWoosh 不熟悉,但他们确实在此处提供了如何使用 Build 实现此目的的指南: http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/

    您是否遵循了每一步?

    【讨论】:

    • 是的,那是我参考的指南,我也遵循了。仍然无法注册设备。
    【解决方案3】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多