0

So i send push notifications using the arrowdb and cloud service with Appcelerator. This seems to work well and the iphone gets the notification. What i wonder is if there is some easy way to clear the badge numer to 0? It needs to be reset at the arrowdb server as well (or apple) i guess.

I want the badge to be reset every time the app is opened.

What i did was adding a resume listener in 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?

4

3 回答 3

4

你试过这个吗?

Titanium.UI.iOS.appBadge = 0
于 2016-06-06T20:46:16.290 回答
0

安卓使用:Ti.Android.NotificationManager.cancelAll()

此命令清除通知和徽章

于 2019-01-25T14:52:30.087 回答
0

清理徽章编号,在我前段时间做的一个项目中,我成功使用了

Ti.UI.iPhone.setAppBadge(0);

希望它也对你有用。

于 2016-06-06T20:48:26.777 回答