[英]Clearing badge number Appcelerator studio, arrowdb and iOS?
So i send push notifications using the arrowdb and cloud service with Appcelerator. 因此,我使用带Appcelerator的arrowdb和云服务发送了推送通知。 This seems to work well and the iphone gets the notification. 这似乎运行良好,并且iPhone收到了通知。 What i wonder is if there is some easy way to clear the badge numer to 0? 我想知道是否有一些简单的方法可以将徽章编号清除为0? It needs to be reset at the arrowdb server as well (or apple) i guess. 我猜也需要在arrowdb服务器(或Apple)上将其重置。
I want the badge to be reset every time the app is opened. 我希望每次打开应用程序时重置徽章。
What i did was adding a resume listener in alloy.js 我所做的是在Alloy.js中添加简历侦听器
Ti.App.addEventListener("resumed", function(e){
In the event listener i first do (to reset the badge locally): 在事件监听器中,我首先要做(在本地重置徽章):
Cloud.PushNotifications.resetBadge({
device_token: device_token
}, function (e) {
if (e.success) {
Ti.API.info('Badge Reset!');
}
else {
Ti.API.error(e);
}
});
Then i also send a push to clear the badge on the server like this by sending a push to ourself: 然后,我还通过向自己发送推送来发送推送以清除服务器上的徽章,如下所示:
var push_payload = {
badge:0,
sound:"",
alert:"",
title:"",
message_text:"",
push_type:"clear",
from_user:Alloy.Globals.currentUser.id,
vibrate:false
};
Cloud.PushNotifications.notify({
channel: 'private_message',
payload: push_payload,
to_ids: Alloy.Globals.currentUser.id
}, function (e) {
if (e.success) {
Ti.API.info('Success sending push notification');
} else {
Ti.API.info('Error sending push: '+((e.error && e.message) || JSON.stringify(e)));
}
});
The event listener seems to be called, and the push is sent. 似乎调用了事件侦听器,并发送了推送。 But somehow the badge still remains on the iphone device... Should I do this differently? 但是徽章仍然以某种方式保留在iphone设备上...我应该采取其他方式吗?
你尝试过这个吗?
Titanium.UI.iOS.appBadge = 0
to clean the badge number, in a project I did some times ago, I successfully used 清理徽章编号,在我之前做过的一个项目中,我成功使用了
Ti.UI.iPhone.setAppBadge(0);
Hope it will work for you too. 希望它也对您有用。
For Android use: Ti.Android.NotificationManager.cancelAll()
对于Android使用: Ti.Android.NotificationManager.cancelAll()
This command clears the notification and badge 此命令清除通知和徽章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.