WP7中Push Notifaction中Tile and Toast应用简单介绍

推送通知的简介:

Windows Phone 7 上的一个新功能-Push Notification Service,一个由应用程序供货商与手机用户进行沟通的管道,服务应用程序可以利用这个功能将讯息广播给所有订阅此服务的手机使用者,如同简讯一般

推送通知的意义:

过去移动应用程序需要经常主动访问相应的WEB服务,以了解是否有任何等待处理的通知。这样做是有效的,但会导航手机无线设备频繁打开,从而对电池续航时 间或者用户的流量带来负面 影响。使用推送通知的方式取代主动调查,Web Service 能够提醒应用程序获取所需要的重要理更新。

推送消息过程

(1)WP设备到MSNS注册PN服务,并得到唯一的服务URI
  (2)WP设备把服务URI传递给Cloud服务,并注册
  (3)当有更新消息发生是,Cloud服务往MSNS发送更新消息
 (4)MSNS把更新消息发送到WP设备上
 (5)需要时WP设备往Cloud服务读取更多的数据

推送通知的类型:

Web service可以使用三种类型的推送通知类型给app发送数据信息:Tile, toast, and raw notifications。

Tile:Every application has one assigned 'Tile'. A Tile displays in the Start screen if the end user has pinned it. Three elements of the Tile can be updated: count, Title, Background. Count can’t display on view when count value is zero.

 

Toast:They are displayed at the top of the screen for ten seconds before disappearing. If the toast notification is tapped, the application that sent the toast notification will launch. A toast notification can be dismissed with a flick(如果想要关闭toast notification需要轻轻向右滑动toast即可). Two text elements of a toast notification can be updated: Title and Sub-title as below

Title(Hello Toast) :A bolded string that displays immediately after the application icon.

Sub-title(FirstToast):A non-bolded string that displays after the Title.

Raw: when app is running, raw notification will display on customered area, otherwise the raw notification is discarded on the Microsoft Push Notification Service and is not delivered to the device.

Tile Toast Raw总结:Tile的push notification显示需要pin to start到手机首页,这样web service服务器如果有更新的时候就会显示出来,Toast的显示是在屏幕的顶部,只有Raw的显示更新是在应用程序正在运行的时候。

以下举例简单说明一下toast和tile的简单使用

Toast的简单使用:

如果我们想要实现在屏幕的顶端显示toast通知,首先需要引用命名空间:using Microsoft.Phone.Shell;

接着产生一个ShellToast对象,对其Title和Sub-title进行初始化,其对应的属性是Title和Content.

这里我使用的是线程对其UI内容进行更新和显示。当点击button事件以后的实现代码:

  ThreadStart threadDelegate = new ThreadStart(this.showToastMessage);

            //ThreadStart threadDelegate = this.showToastMessage;当使用委托的时候,我们可以直接将一个方法绑定到委托变量上,也可以使用上面的new ThreadStart(this.showToastMessage)的方法来实现,因为即使你没有写new编译器在编译的时候会自动加上,所以这两种方式都可以实现将一个方法绑定到委托变量上。

            Thread newThread = new Thread(threadDelegate);

            newThread.Start();

 

   public void showToastMessage()

  {

     Dispatcher.BeginInvoke(() =>

    {

     System.Threading.Thread.Sleep(2000);

     ShellToast toast = new ShellToast();

     toast.Title = "Hello Toast";

     toast.Content = "FirstToast";

     toast.Show();

     toast.NavigationUri = new Uri("/MainPage.xaml", UriKind.Relative);

       });

    }

注意:因为在工作线程中我们不能直接更新UI界面显示,所以要使用BeginInvoke()进行UI界面的更新。

在进行以上的操作之后,启动应用程序,点击界面上的button按钮,再按start按键回到首页界面2秒之后会看见一个如下的toast notifaction出现在屏幕的上方:

Tile的使用:Tile和Toast的push notification使用同样的命名空间:using Microsoft.Phone.Shell;

接着产生ShellTile和StandardTileData对象如下(以下是在MainPage的构造函数中实现):

ShellTile defaultTile = ShellTile.ActiveTiles.First();

//ShellTile.ActiveTiles.First()方法来获取应用最主要的ShellTile.每个应用至少会有一个Tile.也就是获得第一个原有的Tile.

StandardTileData tileData = new StandardTileData()

 {

    Title = "Tile",

    Count = 0,

    BackgroundImage = new Uri("ApplicationIcon.png", UriKind.Relative),

    BackTitle = "TitleTest",

    BackBackgroundImage = new Uri("ApplicationIcon.png", UriKind.Relative), //当然,这里的图片可以使用本地的,也可以加载网络上面的。

    BackContent = new DateTime().Date.DayOfWeek.ToString(),

  };

defaultTile.Update(tileData);

对StandardTileData对象的属性解释如下:上面的属性可以将其分成两组理解,第一组三个属性Title,Count,BackgroundImage和第二组BackTitle,BackBackgroundImage,BackContent。第一组属性是应用程序显示的时候的Tile信息内容如下

,而第二组属性是当Live Tile翻页的时候显示的Tile内容如下

,你可以将其理解成一页扑克牌的正反两面。第一组是扑克牌正面的信息,第二组是扑克牌反面的信息。

最后运行应用程序,效果如下图所示(含有Tile和Toast):

 

 

转载于:https://www.cnblogs.com/zeiier86/archive/2012/03/05/2380533.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值