【问题标题】:Update all tile sizes in WIndows 8 app with periodic notification使用定期通知更新 WIndows 8 应用程序中的所有磁贴大小
【发布时间】:2013-12-23 22:48:11
【问题描述】:

我有一个应用程序框架(在 JavaScript 中),它可以动态设置动态磁贴提要的 URL。在我的代码中,我有类似下面的内容,这适用于宽磁贴,但是当我将磁贴调整为“中”(或“小”)时,实时提要/更新消失了。如果我将大小调整回宽,它就可以了。没有其他磁贴设置(它使用默认设置)。

我的问题是:是否可以同时更新所有图块大小,还是我必须使用getTemplateContent() 和TileUpdater 的update() 方法构建一个完整的XML 对象?

我目前像这样更新定期 URL(同样,这适用于宽图块):

var updater = Windows.UI.Notifications.TileUpdateManager.createTileUpdaterForApplication();
updater.clear();
updater.stopPeriodicUpdate();
updater.enableNotificationQueue(true);
updater.startPeriodicUpdateBatch(
    [ new Windows.Foundation.Uri(feedUrlString) ],
    Windows.UI.Notifications.PeriodicUpdateRecurrence.halfHour
);

【问题讨论】:

    标签: winjs windows-8.1 live-tile


    【解决方案1】:

    要在一次更新中更新多个切片大小,该更新的 XML 负载必须包含每个切片大小的单独元素。

    您可以在 SDK 中的 App tiles and badges sample 中看到这一点。例如,场景 1 演示了如何使用 (a) C# NotificationExtensions 库、(b) 将 XML 构建为字符串以及 (c) 使用 getTemplateContent 来执行此操作。其中一种方法应该适合您。

    举一个案例 (a) 的例子,下面是场景 1 中的代码,其中还包含解释更多内容的注释:

    // This sample application supports all four tile sizes – small (Square70x70), medium (Square150x150), wide (Wide310x150) and large (Square310x310).
    // This means that the user may have resized their tile to any of these four sizes for their custom Start screen layout.
    // Because an app has no way of knowing what size the user resized their app tile to, an app should include template bindings
    // for each supported tile sizes in their notifications. The only exception is the small (Square70x70) tile size because this size
    // does not support live tile notifications, which is why there are no Square70x70 tile templates.
    // We assemble one notification with three template bindings by including the content for each smaller
    // tile in the next size up. Square310x310 includes Wide310x150, which includes Square150x150.
    // If we leave off the content for a tile size which the application supports, the user will not see the
    // notification if the tile is set to that size.
    
    // Create a notification for the Square310x310 tile using one of the available templates for the size.
    var tileContent = NotificationsExtensions.TileContent.TileContentFactory.createTileSquare310x310Text09();
    tileContent.textHeadingWrap.text = "Hello World! My very own tile notification";
    
    // Create a notification for the Wide310x150 tile using one of the available templates for the size.
    var wide310x150Content = NotificationsExtensions.TileContent.TileContentFactory.createTileWide310x150Text03();
    wide310x150Content.textHeadingWrap.text = "Hello World! My very own tile notification";
    
    // Create a notification for the Square150x150 tile using one of the available templates for the size.
    var square150x150Content = NotificationsExtensions.TileContent.TileContentFactory.createTileSquare150x150Text04();
    square150x150Content.textBodyWrap.text = "Hello World! My very own tile notification";
    
    // Attach the Square150x150 template to the Wide310x150 template.
    wide310x150Content.square150x150Content = square150x150Content;
    
    // Attach the Wide310x150 template to the Square310x310 template.
    tileContent.wide310x150Content = wide310x150Content;
    
    // Send the notification to the application’s tile.
    Windows.UI.Notifications.TileUpdateManager.createTileUpdaterForApplication().update(tileContent.createNotification());
    

    【讨论】:

    • 有趣...我从没想过将其他模板内容附加到逐渐变大的磁贴内容对象上。这似乎真的很奇怪。我试试看,谢谢回答!
    • 是的,我同意这有点违反直觉,但这是要走的路:)
    • 不幸的是,这不起作用。这是一种将通知推送到现有磁贴的方法,但它不会更新磁贴上的定期通知。我在问题中的代码确实如此,但仅限于宽瓷砖。我仍然没有办法更新所有磁贴大小的定期通知。
    • 定期更新的 XML 来自服务器,因此您必须实现服务器代码以生成相同的 XML。幸运的是,Notifications Extensions 库可以在服务器上的 ASP.NET 页面中使用,所以上面的代码仍然有效。详情见我的帖子blogs.msdn.com/b/windowsappdev/archive/2013/03/04/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    相关资源
    最近更新 更多