2

我一直在尝试使用 phonegap(适用于 Android)将 pushwoosh 实现到我的基于 javascript 的应用程序中。

我已经浏览了他们的教程和示例,我还可以将设备注册到 GCM 服务器以获取通知。但不知何故,我没有收到注册设备的回调。

代码在这里:

function initPushwoosh()
{
var pushNotification = window.plugins.pushNotification;
pushNotification.onDeviceReady();

//projectid: "581719621125", appid : " EB8C9-89549"
pushNotification.registerDevice({
    projectid: CONFIG.projectID, 
    appid : CONFIG.appId
},
function(token) {
    console.warn('Push token onPushwooshInitialized : ' + pushToken);
    onPushwooshInitialized(token);
},
function(status) {
    console.warn(JSON.stringify(['failed to register ', status]));
});

document.addEventListener('push-notification', function(event) {
    var title = event.notification.title;
    var userData = event.notification.userdata;

    if(typeof(userData) != "undefined") {
        console.warn('user data: ' + JSON.stringify(userData));
    }

    navigator.notification.alert(title);

    pushNotification.stopGeoPushes();
});

}

如您所见,registerDevice 采用的第一个函数用于成功回调,另一个用于失败/错误。

我在 eclipse Log Cat ( Console ) 中看到的是这样的

03-19 10:23:35.339: V/GCMRegistrar(548): 在服务器上注册: true
03-19 10:23:35.369: W/dalvikvm(548): 异常 Ljava/lang/RuntimeException; 在 Landroid/os/AsyncTask 期间抛出;。
03-19 10:23:35.399: W/PushWoosh DeviceFeature2_5(548): 尝试发送 AppOpen
03-19 10:23:36.669: I/global(548): BufferedInputStream 构造函数中使用的默认缓冲区大小。如果需要 8k 缓冲区,最好是明确的。
03-19 10:23:36.669: W/PushWoosh: NetworkUtils(548): PushWooshResult: {"status_code":200,"status_message":"OK","re​​sponse":null}
03-19 10:23:36.679: W/PushWoosh DeviceFeature2_5(548): 发送 AppOpen 成功
03-19 10:23:36.749: I/dalvikvm(548): 在先前失败的类 Lcom/arellomobile/android/push/utils/WorkerTask 上拒绝重新初始化;v=0x0
03-19 10:23:36.749: W/DeviceRegistrar(548): 尝试注册推送
03-19 10:23:37.569: I/global(548): BufferedInputStream 构造函数中使用的默认缓冲区大小。如果需要 8k 缓冲区,最好是明确的。
03-19 10:23:37.580: W/PushWoosh: NetworkUtils(548): PushWooshResult: {"status_code":200,"status_message":"OK","re​​sponse":null}
03-19 10:23:37.590: V/GCMRegistrar(548): 设置在服务器上注册状态为: true
03-19 10:23:38.039:W/PushEventsTransmitter(548):没有 android.permission.BROADCAST_STICKY。恢复为简单广播
03-19 10:23:38.120: W/DeviceRegistrar(548): Registered for pushes: APA91bFK0pv-d1gorQOs2lY_CJMYlNCkoLPWlHsO7oZyLa4gLzQqHnKGKW0mUyiW-llXpoWGpPpLPJAm1vY-Bxi_jnG462NIg2r7gvszqJBQt3wY69WsKnhq-_dgsqXRJ_m_KhoP4uS-2k7FM68LEs3cnCLZqjXHiA

如您所见,最后一行表示设备已成功注册,并且有从服务器获取的 Token/Registration Id,但由于它没有调用我的回调函数,我无法处理这些事情。你已经用谷歌搜索并没有找到解决方案,我不确定他们在我这边的代码中是否有任何逻辑问题。非常感谢任何有用的链接和支持。

4

1 回答 1

0

请从以下网址获取新的 Pushwoosh.jar: https ://github.com/shaders/phonegap-cordova-push-notifications/tree/master/Android/lib

或在这里: https ://github.com/shaders/push-notifications-sdk/tree/master/SDK/Android

(他们是一样的)

您看到的行为是由于这一行:03-19 10:23:38.039: W/PushEventsTransmitter(548): No android.permission.BROADCAST_STICKY。恢复为简单广播

有两种方法可以将注册传输到应用程序,Phonegap Pushwoosh 插件尚不支持这种方式(广播)。不知何故,这种变化设法摆脱了......

更新到新的 Pushwoosh.jar 应该会有所帮助。请让我知道进展如何。

于 2013-03-27T15:36:48.250 回答