设为首页 收藏本站
查看: 877|回复: 0

Windows 8学习笔记(十)----Notification

[复制链接]

尚未签到

发表于 2015-5-22 09:09:59 | 显示全部楼层 |阅读模式
  WinRT中Notification有三种类型:
  Badge:徽章、标记的推送更新,主要对于磁砖进行通知
  Toast:土司推送,一般是程序运行时通知
  Tile:磁砖推送,自然就是程序处理休眠状态时的通知
  注意:这里有消息内容都是以XML内容模板发送的
  
  先研究下磁砖的推送Badge和Tile
  Badge
  了解一下有哪些方法
  BadgeNotification(XmlDocument content)
  BadgeUpdateManager
  CreateBadgeUpdaterForApplication()---为当前应用更新磁砖
  CreateBadgeUpdaterForApplication(string applicationID)---为指定的应用更新磁砖
  有个疑问,这里的applicationID一般在哪儿得到??还望知道的告知一下哦~
  CreateBadgeUpdaterForSecondaryTile(string tileID)—为指定的磁砖更新
  GetTemplateContent(BadgeTemplateType type)—获取预定义好的XML徽章模板
  BadgeUpdater
  Update(BadgeNotification notification)
  
  示例代码:
XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
// We are setting attribute value 6
badgeElement.SetAttribute("value", "6");
// Create a badge notification from XML
BadgeNotification badgeNotification = new BadgeNotification(badgeXml);
// Send the notification to the secondary tile
BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(MainPage.dynamicTileId);
badgeUpdater.Update(badgeNotification);  

  Tile
  它包含的方法跟Badge类似
  TileNotification(XmlDocument document)
  TileUpdateManager
  包手中四个方法,跟BadgeUpdateManager类似
  CreateTileUpdaterForApplication()
  CreateTileUpdaterForApplication(string applicationID)
  CreateTileUpdaterForSecondaryTile(string tileID)
  GetTemplateContent
  TileUpdater--Update(TileNotificaton notification)
  示例代码:

XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText04);
// Refer to template documentation to determine how many text fields a particular template has
// get the text attributes for this template and fill them in
XmlNodeList tileTextElements = tileXml.GetElementsByTagName("text");
tileTextElements.Item(0).AppendChild(tileXml.CreateTextNode("Sent to a secondary tile!"));
XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04);
XmlNodeList squareTileTextElements = squareTileXml.GetElementsByTagName("text");
squareTileTextElements.Item(0).AppendChild(squareTileXml.CreateTextNode("Sent to a secondary tile!"));
// Include the square template in the notification
IXmlNode subNode = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
tileXml.GetElementsByTagName("visual").Item(0).AppendChild(subNode);
// Create the notification from the XML
TileNotification tileNotification = new TileNotification(tileXml);
// Send the notification to the secondary tile by creating a secondary tile updater
TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(MainPage.dynamicTileId);
tileUpdater.Update(tileNotification);
  Toast

  方法和属性也基本类似
  但我下面的代码有问题,没有显示Toast通知,注册Failed事件,跟踪说是应用程序功能会阻止通知传递。 (异常来自 HRESULT:0x803E0112)
  
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
XmlNodeList textNodes = toastXml.GetElementsByTagName("text");
textNodes.Item(0).AppendChild(toastXml.CreateTextNode("Sent to Toast Notification!"));
ToastNotification toastNotification = new ToastNotification(toastXml);
toastNotification.Failed += toastNotification_Failed;
toastNotification.Dismissed += toastNotification_Dismissed;
ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
  在MSDN Sample里有Toast Sample示例,里面封装了NotificationExtensions扩展,很容易就可以实现通知更新,不需要编辑复杂的XML模板,但很纠结,我上面的代码有啥问题??
  
  NotificationsExtensions微软示例给我们封装的类库,非常方便,得学习一下大师的封装逻辑。。。
  
  磁砖的更新还算简单,PushNotification有点摸不着头脑,首先PushChannel都是要手动输入,这个不是生成的么,很纠结,还希望有研究的同胞能提供点学习资料,跟Phone7的机制不太一样呢?!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-69401-1-1.html 上篇帖子: Windows phone 8 学习笔记(4) 应用的启动 下篇帖子: Windows 8 下利用VS11开发初体验
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表