2013-01-15 45 views
1

我目前正在研究HTML5/JavaScript中的图片阅读器应用程序,并且我遇到了活动图块的问题。 我有一个活动磁贴,通过查询返回博客最新3篇文章的Web服务定期更新。 活动图块按预期工作,但我想创建一个徽章通知来显示未读文章。WinRT活动图块徽章更新

我认为这样做的方式是查看图块是否更新,然后从徽章通知中增加数字。当用户启动应用程序时,徽章将被清除。

我用下面的代码行:

var notifications = Windows.UI.Notifications; 
    var polledUri = new Windows.Foundation.Uri("http://my_url/feed.php"); 
    var recurrence = notifications.PeriodicUpdateRecurrence.halfHour; 
    var tileUpdater = notifications.TileUpdateManager.createTileUpdaterForApplication() 
    tileUpdater.startPeriodicUpdate(polledUri, recurrence); 

这将创建动态磁贴,更新每半小时一班。我的问题是:我想在每次PeriodicUpdate发生时创建一个徽章更新。我使用下面的代码:

var badgeType = notifications.BadgeTemplateType.badgeNumber; 
    var badgeXml = notifications.BadgeUpdateManager.getTemplateContent(badgeType); 
    var badgeAttributes = badgeXml.getElementsByTagName("badge"); 
    var tileUpdater = notifications.TileUpdateManager.createTileUpdaterForApplication() 
    tileUpdater.startPeriodicUpdate(polledUri, recurrence); 
    // this is where my problem is 
    // if (tileUpdater.update() == true) -> This line is not correct: how can I catch the update event? 
    //badgeAttributes[0].setAttribute("value", currentValue + 1); 
    var badgeNotification = new notifications.BadgeNotification(badgeXml); 
    notifications.BadgeUpdateManager.createBadgeUpdaterForApplication().update(badgeNotification); 

我想赶上那tileUpdater.startPeriodicUpdate功能的更新事件并增加徽章的价值。我怎样才能做到这一点?我到处搜索,找不到答案。

我感谢您的帮助。
Julian Atanasoae

回答

2

即使您可以检测到发生周期性磁贴更新(我敢肯定,您不能),它会在您的应用程序未运行时发生大部分时间。因此,您必须通过“本地通知”设置徽章更新的代码不会执行。事实上,徽章只会在应用程序处于前景时才会更新,并且会定期发出通知(这并不是那么有趣,因为您的应用程序在前景中无法看到拼贴!)。

这听起来像你想通过显示在徽章中的瓦片更新次数? (请注意,最多只能使用99,最大徽章数量)

我想说也使用徽章的定期通知,并且该定期更新的URL端点可能是接受查询的服务字符串参数唯一标识客户端。然后,您的服务将为该客户端生成正确的徽章通知,方法是增加客户端特定的值,即维护服务器端。

尽管如此,您还是会发生两个定期通知,一个用于贴片,另一个用于徽章,虽然您可以将它们安排在相同的时间间隔内,但当它们到达时仍存在潜在的偏差,从预期的时间到15分钟。

0

有2个解决问题的对策:

1)我创建一个徽章更新定期通知我存储的GUID对Web服务的每个客户端。此解决方案适用于不常使用(2000用户以下)的应用程序,因为XML文件会变得太大,Web服务将不得不为每个客户端增加大量值。

2)我用计时器创建后台任务,每15分钟左右检查一次更新。

朱利安