我正在尝试为iOS实施新的PhoneGap PushPlugin,但无法弄清楚为什么我遇到这个问题。
当应用加载时,它成功调用OnDeviceReadyPush函数:
var pushNotification;
function onDeviceReadyPush() {
$("#app-status-ul").append('<li>deviceready event received</li>');
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(successHandler, errorHandler, { "senderID": "661780372179", "ecb": "onNotificationGCM" });
} else {
pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });
}
}
document.addEventListener('deviceready', onDeviceReadyPush, true);
假设有一个tokenHandler函数:
function tokenHandler(result) {
$("#app-status-ul").append('<li>token: ' + result + '</li>');
// 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.
$.get("", { "deviceid": result}, processResult);
function processResult(data, textStatus) {
alert(data);
}
}
在我最小化应用程序然后再回到它之前它不起作用。然后它会触发tokenHandler事件。
请帮助,我一直在看这个尝试我能想到的两天,现在又疯了。
答案 0 :(得分:0)
你试过这个:
document.addEventListener('deviceready', onDeviceReadyPush, FALSE);
答案 1 :(得分:0)
我使用的是错误的cordova文件。在将所有内容更新到当时的最新版本后,它开始按预期工作。