1

我目前正在开发 HTML5/JavaScript 中的提要阅读器应用程序,但我遇到了动态磁贴问题。我有一个实时磁贴,它通过查询从博客返回最新 3 篇文章的 Web 服务定期更新。活动磁贴按预期工作,但我想创建一个显示未读文章的徽章通知。

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

我使用以下代码行:

    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 函数的更新事件并增加徽章的值。我怎样才能做到这一点?我到处搜索,但找不到答案。

我感谢您的帮助。
朱利安·阿塔纳索埃

4

2 回答 2

2

即使您可以检测到已经发生了定期磁贴更新(我很确定您不能),它也会在您的应用程序未运行的大部分时间发生。因此,您必须通过“本地通知”设置徽章更新的代码将不会执行。事实上,徽章只会在应用程序处于前台并且定期通知命中时更新(这并不是那么有趣,因为您的应用程序处于前台时,您无论如何都看不到磁贴!)。

听起来您想通过在徽章中显示磁贴来跟踪磁贴的更新次数? (请注意,最多只能使用 99,最大徽章数)

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

即使这样,您也会有两个定期通知发生,一个用于磁贴,一个用于徽章,虽然您可以将它们安排在相同的时间间隔,但它们到达时仍然存在潜在的偏差,最多 15 分钟所需的时间。

于 2013-01-16T06:14:18.890 回答
0

这个问题有2个解决方案:

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

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

朱利安

于 2013-01-18T07:51:05.703 回答