【发布时间】:2016-11-01 20:43:38
【问题描述】:
我的应用确实收到了来自 GCM 的推送通知。 然后在我的 iOS 设备中,图标上显示的数字等于数量或收到的通知。
我想在打开应用程序时清除它。 根据文档,我必须使用这些代码行:
push.clearAllNotifications(function() {
alert("1");
}, function() {
alert("2");
});
但是,此后的所有代码都不起作用,两个警报之一也没有显示。当然,数字仍然显示在图标上。 任何提示或替代方法?
编辑: 我当前的代码:
function startPush() {
var push = PushNotification.init({
android: {
senderID: "xxxx",
vibrate: true
},
ios: {
senderID: "951044503850",
gcmSandbox: false,
alert: "true",
badge: true,
sound: 'false',
clearBadge: "true"
}
});
push.on('registration', function(data) {
var regID = data.registrationId;
alert(regID);
//this works
});
push.clearAllNotifications(function() {
alert("1");
//does not fire
}, function() {
alert("2");
// does not fire
});
}
我确实收到了一个registrationId,所以这部分确实有效。但是警报(1)或警报(2)不会触发,因此这部分不起作用。 顺便说一句,奖励积分;),我的手机也不会在推送通知时振动
【问题讨论】:
-
你初始化 push 变量了吗?
-
@jcesarmobile 我编辑了我的“问题”,现在你可以看到我做了什么。事实上,我确实获得了一个有效的registrationId,并且它有效,我可以发送推送通知,我认为我可以声明推送变量已被初始化。
标签: javascript cordova notifications