我一直在尝试使用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): Is registered on server: true03:19 10:23:35.369: W/dalvikvm(548): Exception Ljava/lang/RuntimeException;在landoid/os/AsyncTask期间抛出。03-19 10:23:35.399: W/PushWoosh DeviceFeature2_5(548): Try To send apppopen[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","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):在先前失败的类Lcom/arellomile/android/push/utils/WorkerTask上拒绝重新初始化;v = 0 x003:19 10:23:36.749: W/DeviceRegistrar(548): Try To Registered for pushing .日志示例[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","response":null}03:19 10:23:37.590: V/GCMRegistrar(548): Setting registered on server status为:true03-19 10:23:38.039: W/pusheventstranster (548): No android.permission.BROADCAstrongTICKY. permission. permission. read ->恢复到简单广播03-19 10:23:38.120: W/DeviceRegistrar(548): Registered for push: ap91bfk0pv - d1gorqos2ly_cjmylnckolpwlhso7ozyla4glzqqhnkgkw0muyiw - llxpowgppplpjam1vy - bxi_jng462nig2r7gvszqjbqt3wy69wsknhq -_dgsqXRJ_m_KhoP4uS-2k7FM68LEs3cnCLZqjXHiA之前正如您所看到的,最后一行表示设备已成功注册,并且有从服务器获得的令牌/注册Id,但由于它没有调用我的回调函数,因此我无法处理这些事情。你已经谷歌了,没有找到解决方案,我不确定我这边的代码是否有任何逻辑问题。
请从以下地址获取新的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/pusheventstranster (548): No android.permission.BROADCAstrongTICKY. permission. permission. read ->恢复到简单广播
有两种方式传输注册到应用程序,这种方式(广播)不支持Phonegap Pushwoosh插件。不知何故,这个更改成功地泄露了…
更新到新的Pushwoosh.jar应该有帮助。请让我知道结果如何