寄存器设备上的Pushwoosh回调

时间:2013-03-19 05:04:00

标签: javascript cordova push-notification android-notifications pushwoosh

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

我已经完成了他们的tuturials和示例,我也能够将设备注册到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(控制台)中看到的是它显示的内容

03-19 10:23:35.339: V/GCMRegistrar(548): Is registered on server: true
03-19 10:23:35.369: W/dalvikvm(548): Exception Ljava/lang/RuntimeException; thrown during Landroid/os/AsyncTask;.
03-19 10:23:35.399: W/PushWoosh DeviceFeature2_5(548): Try To sent AppOpen
03-19 10:23:36.669: I/global(548): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
03-19 10:23:36.669: W/PushWoosh: NetworkUtils(548): PushWooshResult: {"status_code":200,"status_message":"OK","response":null}
03-19 10:23:36.679: W/PushWoosh DeviceFeature2_5(548): Send AppOpen success
03-19 10:23:36.749: I/dalvikvm(548): Rejecting re-init on previously-failed class Lcom/arellomobile/android/push/utils/WorkerTask; v=0x0
03-19 10:23:36.749: W/DeviceRegistrar(548): Try To Registered for pushes
03-19 10:23:37.569: I/global(548): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
03-19 10:23:37.580: W/PushWoosh: NetworkUtils(548): PushWooshResult: {"status_code":200,"status_message":"OK","response":null}
03-19 10:23:37.590: V/GCMRegistrar(548): Setting registered on server status as: true
03-19 10:23:38.039: W/PushEventsTransmitter(548): No android.permission.BROADCAST_STICKY. Reverting to simple broadcast
03-19 10:23:38.120: W/DeviceRegistrar(548): Registered for pushes: APA91bFK0pv-d1gorQOs2lY_CJMYlNCkoLPWlHsO7oZyLa4gLzQqHnKGKW0mUyiW-llXpoWGpPpLPJAm1vY-Bxi_jnG462NIg2r7gvszqJBQt3wY69WsKnhq-_dgsqXRJ_m_KhoP4uS-2k7FM68LEs3cnCLZqjXHiA

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

1 个答案:

答案 0 :(得分: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):没有android.permission.BROADCAST_STICKY。恢复简单广播

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

更新到新的Pushwoosh.jar应该会有所帮助。请告诉我它是怎么回事。