Distriqt AIR Local Notification Ane - 删除旧通知

时间:2013-02-22 23:44:11

标签: mobile air notifications push-notification local

我们尝试实现distriqt的好本地通知扩展。

使用deactivate事件设置了新通知:

 notification.id        = int(Math.random()*100);
                    notification.tickerText = _asde + " asdasd!";
                    notification.title      = _asde + " asd!";
                    notification.body       = "asd!";
                    notification.iconType   = NotificationIconType.APPLICATION;
                    notification.count      = 0;
                    notification.repeatInterval = 0;
                    notification.vibrate    = false;
                    notification.playSound  = true;
                    notification.soundName  = "assets/sounds/notification.mp3";

                    notification.delay      = secondsToDeath;
                    notification.data       = "Some notification data to attach "+notification.id;
try
                {
                    Notifications.service.notify( notification.id, notification );

                    _count ++;
                    Notifications.service.setBadgeNumber( _count );
                }
                catch (e:Error)
                {

                }

如果用户点击该应用并再次停用该应用,则会设置新通知。

旧的通知仍然可用并显示但我们希望删除旧的通知。 我们还没有找到取消注册旧通知的方法。

有什么想法吗?

        private static const DEACTIVATE_NOTIFICATION_ID_4 : int = 4;

宣布。

if(_GoodA == true){
                    setSpielenFertigDate.time = 2400000*(1-_aktuellerFreudeWert/_maximalerFreudeWert);
                    var secondsToSpielenFertig:int = int((setSpielenFertigDate.time)/ 1000);

                    trace("halloe" + _fernseherAn.toString());
                    notification4.id        = DEACTIVATE_NOTIFICATION_ID_4;
                    notification4.tickerText = "He test it!";
                    notification4.title         = "sdf is happy!";
                    notification4.body      = "sdf test is on!";
                    notification4.iconType  = NotificationIconType.APPLICATION;
                    notification4.count     = 0;
                    notification4.repeatInterval = 0;
                    notification4.vibrate   = false;
                    notification4.playSound  = true;
                    notification4.soundName  = "assets/sounds/notification.mp3";

                    notification4.delay     = secondsToSpielenFertig;
                    notification4.data      = "Some notification data to attach "+ notification4.id;

                    try
                    {
                        Notifications.service.notify( notification4.id, notification4 );

                        _count ++;
                        Notifications.service.setBadgeNumber( _count );
                    }
                    catch (e:Error)
                    {

                    }
                }
                else{
                    trace("halloe2" + _fernseherAn.toString());
                    setSpielenDate.time = 5100000*(_aktuellerFreudeWert/_maximalerFreudeWert);
                    var secondsToSpielen:int = int((setSpielenDate.time)/ 1000);


                    notification4.id        = DEACTIVATE_NOTIFICATION_ID_4;
                    notification4.tickerText = "He tested it!";
                    notification4.title         = "sdf is unhappy!";
                    notification4.body      = "sdf test is off!";
                    notification4.iconType  = NotificationIconType.APPLICATION;
                    notification4.count     = 0;
                    notification4.repeatInterval = 0;
                    notification4.vibrate   = false;
                    notification4.playSound  = true;
                    notification4.soundName  = "assets/sounds/notification.mp3";
                    //Sekunden bis Nachricht geschickt wird
                    notification4.delay     = secondsToSpielen;
                    notification4.data      = "Some notification data to attach "+notification4.id;

                    try
                    {
                        Notifications.service.notify( notification4.id, notification4 );

                        _count ++;
                        Notifications.service.setBadgeNumber( _count );
                    }
                    catch (e:Error)
                    {

                    }
                }

如果触发了应用程序的deactivate事件,则会跟踪if和else子句的正确部分。但它不会更新正文和标题......

1 个答案:

答案 0 :(得分:0)

使用我们的扩展程序有两种方法可以做到这一点。两者都涉及跟踪通知的ID。

首先是跟踪您的上一个通知并从通知区域“取消”它。为此,您需要至少存储上次创建的通知的ID。您可能感兴趣的代码部分是取消功能,这会通过指定要删除的通知的ID从通知面板中删除通知。

你班级的某个地方宣布对最后一个通知的引用:

private var _lastNotification : Notification;

然后在你的去激活处理程序中:

var notification:Notification = new Notification();
notification.id = int(Math.random()*100);
notification.tickerText = "Deactivated";
notification.title = "TEST";
notification.body = "Application Deactivated";

if (_lastNotification != null)
    Notifications.service.cancel( _lastNotification.id );
Notifications.service.notify( notification.id, notification );

// Set this to be the recent notification displayed
_lastNotification = notification;

第二个选项是为所有停用通知使用单个通知ID。在这种情况下,您可以选择用于通知的常量ID,并根据需要更新通知。通知管理器不会显示其他通知,只是更新具有指定ID的通知(如果用户已关闭,则显示该通知)。

private static const DEACTIVATE_NOTIFICATION_ID : int = 10;

var notification:Notification = new Notification();
notification.id = DEACTIVATE_NOTIFICATION_ID;
notification.tickerText = "Deactivated";
notification.title = "TEST";
notification.body = "Application Deactivated";

Notifications.service.notify( notification.id, notification );

希望这有帮助!