我正在尝试使用 XML 直接更新 Windows 8 辅助磁贴。但是,我不断收到一个异常,即我固定的图块的标识符无效。我什至尝试直接从 Windows 中提取标识符,然后将其替换回CreateTileUpdaterForSecondaryTile
,但我仍然遇到同样的异常。这是我的代码:
public async static void UpdateSecondarySectionTile()
{
string tileXmlString = "<tile id='SecondaryTile-7-0'>"
+ "<visual>"
+ "<binding template='TileWideImage'>"
+ "<image id='1' src='" + imageSource + "' alt='alt text'/>"
+ "</binding>"
+ "</visual>"
+ "</tile>";
// create a DOM
Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument();
tileDOM.LoadXml(tileXmlString);
System.Collections.Generic.IReadOnlyList<Windows.UI.StartScreen.SecondaryTile> tileList = await Windows.UI.StartScreen.SecondaryTile.FindAllAsync();
foreach (var tile in tileList)
{
string tileId = tile.TileId;
Windows.UI.Notifications.TileNotification tileUpdate = new Windows.UI.Notifications.TileNotification(tileDOM);
try
{
Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).Update(tileUpdate);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("message: " + e.Message + ", inner exception: " + e.InnerException + " string: " + e.ToString());
}
}
}
调试行输出:
//message: The application identifier provided is invalid.
, inner exception: string: System.Exception: The application identifier provided is invalid.
知道问题是什么吗? foreach 循环仅执行一次,因为我的构建中只有一个固定的辅助图块。 (我也意识到UpdateSecondarySectionTile
应将tileId作为参数,并且每次调用仅更新一个图块;这只是调试代码。)
我觉得很有趣的是它在抱怨应用标识符而不是tile标识符。另外,我知道如果您运行磁贴更新,有时它们会不起作用在模拟器中 http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/90f558c3-e9bf-47ce-a066-43f1bfcdee20,但即使在我的本地计算机上我也遇到了这个问题。
问题中引用的异常(“提供的应用程序标识符无效”)可以由CreateTileUpdaterForSecondaryTile
如果辅助图块最初是在模拟器中固定的,则在模拟器之外的方法。要解决此问题,请取消固定辅助图块并在模拟器外部重新固定它。
正如问题作者所指出的,模拟器不支持磁贴更新 API(以及其他推送通知相关的 API)。在这种情况下,辅助图块固定不会在模拟器外部持续存在。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)