Windows Phone 7推送通知架构解析:实践编程技巧详解?
- 内容介绍
- 文章标签
- 相关推荐
本文共计4386个文字,预计阅读时间需要18分钟。
作品目标:Windows Phone 7 开发实用手册内容概要:Windows Phone 推送通知类型Windows Phone 中存在三种默认通知类型:Tile、Push 和 Toast 通知。Tile 通知:每个应用程序可设置 Tile,显示应用内容的可视化摘要。
作品目标:Windows Phone 7 开发的实用手册 Windows Phone推送通知类型 Windows Phone中存在三种默认通知类型:Tile、Push 和 Toast 通知。 Tile通知 每个应用程序可设置Tile—应用程序内容的可视化、 动态的表示形式。当应用程序被固定显示在启动屏幕(Start Screen)时,我们就可以看到Tile的信息。Tile可以修改的三个元素包括:计数(Count)、标题(Title)和背景图像(Background)。 Toast通知 Toast通知是Windows Phone系统通知,且不破坏用户的工作流,十秒钟后自动消失。Toast通知显示在屏幕的顶部。 Toast通知的两个文本元素:标题和副标题。标题为粗体字显示的字符串,副标题为非粗体字显示的字符串。- Window Phone客户端应用程序请求与微软推送通知服务(Microsoft Push Notification Services)建立通道连接,微软推送通知服务(Microsoft Push Notification Services)使用通道URI响应。
- Window Phone客户端应用程序向监视服务(Web Service或者Cloud Application)发送包含推送通知服务通道URI以及负载的消息。
- 当监视服务检测到信息更改时(如航班取消、航班延期或天气警报),它会向微软推送通知服务(Microsoft Push Notification Services)发送消息。
- 微软推送通知服务(Microsoft Push Notification Services)将消息中继到Windows Phone设备,由Window Phone客户端应用程序处理收到的消息。
- RawPushNotificationMessage – 当Windows Phone应用程序运行时,可以接收到来自Web Service的Raw通知消息。
- TilePushNotificationMessage –当Windows Phone应用程序被固定显示在启动页面,Windows Phone将呈现Tile通知消息的内容。
- ToastPushNotificationMessage –发送Toast"警告"消息至Windows Phone。
var tile =new TilePushNotificationMessage
{
BackgroundImageUri = tileImageUri, // Remote or phone-local tile image uri.
Count = tileCount, // Counter between 1 to 99 should be displayed on the tile.
Title = “Tile Title” // Title to be displayed on the tile.
};
// Send the message synchronously.
try
{
var sendResult = tile.Send(phoneChannelUri);
// Check the send result.
}
catch (Exception ex)
{
// Log the error.
}
// Send the message asynchronously.
tile.SendAsync(
phoneChannelUri,
result => {/* Check the send result */},
exception => {/* Log the error */}); 从上面的代码可以看出,发送Tile通知到Windows Phone应用多么简单,仅仅是创建一个新的TilePushNotificationMessage,并设置相关的属性,然后调用同步Send和异步SendAsync的方法即可。 发送Toast通知 下面的代码片段演示了如何使用Windows Phone的推送通知类库以同步和异步的方式发送Toast通知。 // Prepare a toast push notification message.
var toast =new ToastPushNotificationMessage
{
Title = “Title”, // Title to be displayed as the toast header.
Subtitle = “Sub Title” // Message to be displayed next to the toast header.
};
// Send the message synchronously.
try
{
var sendResult = toast.Send(phoneChannelUri);
// Check the send result.
}
catch (Exception ex)
{
// Log the error.
}
// Send the message asynchronously.
toast.SendAsync(
phoneChannelUri,
result => { /* Check the send result */ },
exception => { /* Log the error */ }); 发送Raw通知 下面的代码片段演示了如何使用Windows Phone的推送通知类库以同步和异步的方式发送Raw通知。 C# // Prepare a raw push notification message.
byte[] rawData = {};
var raw =new RawPushNotificationMessage
{
RawData = rawData, // Raw data to be sent with the message.
};
// Send the message synchronously.
try
{
var sendResult = raw.Send(phoneChannelUri);
// Check the send result.
}
catch (Exception ex)
{
// Log the error.
}
// Send the message asynchronously.
raw.SendAsync(
phoneChannelUri,
result => { /* Check the send result */ },
exception => { /* Log the error */ }); Windows Phone客户端设定启动推送通知 我们使用简单的Silverlight应用说明如何将推送通知消息发送到Windows Phone智能手机。 注册推送通知服务 为了接收推送通知消息,Windows Phone应用程序需要向微软推送通知服务MPNS发送注册请求,MPNS返回的Windows Phone智能手机的URI(统一资源标识符)。 在我们的示例中,推送通知PN功能封装在PushContext类。强烈建议您每次启动应用程序时将PN通道URI更新到Web Service,确保您的Web Service中保存的是智能手机最新的URI。 推送通知设置页面 每个Windows Phone应用,如果使用推送通知都必须允许用户设置推送通知功能的开启和关闭。 即程序开启推送通知PN通道时需要得到用户的许可,且用户也可以选择关闭推送通知PN通道。下面的画面(Project : WindowsPhone.Recipes.Push.Client File : Views/PushSettingControl.XAML)显示了示例应用程序的推送通知设定页面。 图 push setting Project : WindowsPhone.Recipes.Push.Client File : Views/PushSettingControl.XAML <UserControl x:Class="WindowsPhone.Recipes.Push.Client.Controls.PushSettingsControl"
xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:converters="clr-namespace:WindowsPhone.Recipes.Push.Client.Converters"
xmlns:d="schemas.microsoft.com/expression/blend/2008"
xmlns:mc="schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="640" d:DesignWidth="480">
<UserControl.Resources>
<converters:BoolBrushConverter x:Key="BoolBrushConverter"/>
<Style x:Key="DescTextStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="14"/>
<Setter Property="Foreground" Value="Silver"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="Margin" Value="16,-38,16,24"/>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<StackPanel>
<StackPanel>
<tk:ToggleSwitch Header="Push Notifications"
IsChecked="{Binding IsPushEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Turn on/off push notifications."/>
</StackPanel>
<Grid>
<StackPanel Margin="16,0,0,0">
<tk:ToggleSwitch Header="Tile Notifications"
IsChecked="{Binding IsTileEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Tile push notifications update the application's tile displayed in the Start Screen. The application must be pinned by the user first."/>
<tk:ToggleSwitch Header="Toast Notifications"
IsChecked="{Binding IsToastEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Toast push notifications are system-wide notifications that do not disrupt the user workflow or require intervention to resolve and are displayed in the top of the screen for ten seconds."/>
<tk:ToggleSwitch Header="Raw Notifications"
IsChecked="{Binding IsRawEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Raw push notifications are used to send application specific information. The application must be running first."/>
</StackPanel>
<Border Background="{Binding IsPushEnabled, Converter={StaticResource BoolBrushConverter}}"/>
</Grid>
</StackPanel>
</Grid>
</UserControl> 当用户登录时,注册PN推送通知的通道。 Project: WindowsPhone.Recipes.Push.Client File: Views/ UserLoginView.xaml.cs privatevoid InternalLogin()
{
login.Visibility = Visibility.Collapsed;
progress.Visibility = Visibility.Visible;
var pushContext = PushContext.Current;
pushContext.Connect(c => RegisterClient(c.ChannelUri));
}
privatevoid RegisterClient(Uri channelUri)
{
// Register the URI with 3rd party web service.
try
{
var pushService =new PushServiceClient();
pushService.RegisterCompleted += (s, e) =>
{
pushService.CloseAsync();
Completed(e.Error);
};
pushService.RegisterAsync(UserName, channelUri);
}
catch (Exception ex)
{
Completed(ex);
}
} 向Web Service提交订阅,创建PN通道 Project: WindowsPhone.Recipes.Push.Client File: PushContext.cs publicvoid Connect(Action<HttpNotificationChannel> prepared)
{
if (IsConnected)
{
prepared(NotificationChannel);
return;
}
try
{
// First, try to pick up an existing channel.
NotificationChannel = HttpNotificationChannel.Find(ChannelName);
if (NotificationChannel ==null)
{
// Create new channel and subscribe events.
CreateChannel(prepared);
}
else
{
// Channel exists, no need to create a new one.
SubscribeToNotificationEvents();
PrepareChannel(prepared);
}
IsConnected =true;
}
catch (Exception ex)
{
OnError(ex);
}
}
publicvoid Disconnect()
{
if (!IsConnected)
{
return;
}
try
{
if (NotificationChannel !=null)
{
UnbindFromTileNotifications();
UnbindFromToastNotifications();
NotificationChannel.Close();
}
}
catch (Exception ex)
{
OnError(ex);
}
finally
{
NotificationChannel =null;
IsConnected =false;
}
} 创建PN通道的具体函数。 Project: WindowsPhone.Recipes.Push.Client File: PushContext.cs ///<summary>
/// Create channel, subscribe to channel events and open the channel.
///</summary>
privatevoid CreateChannel(Action<HttpNotificationChannel> prepared)
{
// Create a new channel.
NotificationChannel =new HttpNotificationChannel(ChannelName, ServiceName);
// Register to UriUpdated event. This occurs when channel successfully opens.
NotificationChannel.ChannelUriUpdated += (s, e) => Dispatcher.BeginInvoke(() => PrepareChannel(prepared));
SubscribeToNotificationEvents();
// Trying to Open the channel.
NotificationChannel.Open();
} 绑定和解除绑定Raw、Tile和Toast通知消息的函数。 Project: WindowsPhone.Recipes.Push.Client File: PushContext.cs private void BindToTileNotifications() { try { if (NotificationChannel != null && !NotificationChannel.IsShellTileBound) { var listOfAllowedDomains = new Collection<Uri>(AllowedDomains); NotificationChannel.BindToShellTile(listOfAllowedDomains); } } catch (Exception ex) { OnError(ex); } } private void BindToToastNotifications() { try { if (NotificationChannel != null && !NotificationChannel.IsShellToastBound) { NotificationChannel.BindToShellToast(); } } catch (Exception ex) { OnError(ex); } } private void UnbindFromTileNotifications() { try { if (NotificationChannel.IsShellTileBound) { NotificationChannel.UnbindToShellTile(); } } catch (Exception ex) { OnError(ex); } } private void UnbindFromToastNotifications() { try { if (NotificationChannel.IsShellToastBound) { NotificationChannel.UnbindToShellToast(); } } catch (Exception ex) { OnError(ex); } } Web Service设计推送通知功能 为了说明如何在Web Service设计推送通知服务功能,我们创建WPF应用程序Push Notifications Server,即Web Service,模拟第三方服务器。在WPF应用程序创建一个WCF服务,让Windows Phone应用订阅通知服务并与MPNS通讯。 WPF应用程序Push Notifications Server有五个选项卡(One-time、 Ask to Pin、 Custom Tile、Counter和Tile Scheduled),One-Time实现次性推送三种类型的通知消息;Counter演示计算器重置;Ask to Pin实现询问用户是否将应用程序固定显示在启动页面;Custom Tile实现定制Tile通知消息Tile Scheduled实现设定Tile更新计划表。下面的章节将详细讲述这五个选项卡的功能。 One-Time--一次性推送三种类型的通知消息 说明 One-Time选项卡是向注册用户提供最简单的推送模式,即一次性将三种类型的推送通知:Raw、Tile和Toast通知推送给Windows Phone。One-Time选项卡显示了三种类型通知的可设置的属性,以及MPNS的返回值类型。 操作
- 运行 WindowsPhone.Recipes.Push.Server 和WindowsPhone.Recipes.Push.Client projects (设置 WindowsPhone.Recipes.Push.Server为默认启动程序)。
- 在Windows Phone模拟器中以任意用户名登录。
- 在服务器端,选择"One Time"选项卡。
- 设置Raw、Tile和Toast消息内容,然后选择"Send"发送。
- URI必须能够访问到手机
- 图像的大小必须小于80KB
- 下载的时间不能超过60秒
本文共计4386个文字,预计阅读时间需要18分钟。
作品目标:Windows Phone 7 开发实用手册内容概要:Windows Phone 推送通知类型Windows Phone 中存在三种默认通知类型:Tile、Push 和 Toast 通知。Tile 通知:每个应用程序可设置 Tile,显示应用内容的可视化摘要。
作品目标:Windows Phone 7 开发的实用手册 Windows Phone推送通知类型 Windows Phone中存在三种默认通知类型:Tile、Push 和 Toast 通知。 Tile通知 每个应用程序可设置Tile—应用程序内容的可视化、 动态的表示形式。当应用程序被固定显示在启动屏幕(Start Screen)时,我们就可以看到Tile的信息。Tile可以修改的三个元素包括:计数(Count)、标题(Title)和背景图像(Background)。 Toast通知 Toast通知是Windows Phone系统通知,且不破坏用户的工作流,十秒钟后自动消失。Toast通知显示在屏幕的顶部。 Toast通知的两个文本元素:标题和副标题。标题为粗体字显示的字符串,副标题为非粗体字显示的字符串。- Window Phone客户端应用程序请求与微软推送通知服务(Microsoft Push Notification Services)建立通道连接,微软推送通知服务(Microsoft Push Notification Services)使用通道URI响应。
- Window Phone客户端应用程序向监视服务(Web Service或者Cloud Application)发送包含推送通知服务通道URI以及负载的消息。
- 当监视服务检测到信息更改时(如航班取消、航班延期或天气警报),它会向微软推送通知服务(Microsoft Push Notification Services)发送消息。
- 微软推送通知服务(Microsoft Push Notification Services)将消息中继到Windows Phone设备,由Window Phone客户端应用程序处理收到的消息。
- RawPushNotificationMessage – 当Windows Phone应用程序运行时,可以接收到来自Web Service的Raw通知消息。
- TilePushNotificationMessage –当Windows Phone应用程序被固定显示在启动页面,Windows Phone将呈现Tile通知消息的内容。
- ToastPushNotificationMessage –发送Toast"警告"消息至Windows Phone。
var tile =new TilePushNotificationMessage
{
BackgroundImageUri = tileImageUri, // Remote or phone-local tile image uri.
Count = tileCount, // Counter between 1 to 99 should be displayed on the tile.
Title = “Tile Title” // Title to be displayed on the tile.
};
// Send the message synchronously.
try
{
var sendResult = tile.Send(phoneChannelUri);
// Check the send result.
}
catch (Exception ex)
{
// Log the error.
}
// Send the message asynchronously.
tile.SendAsync(
phoneChannelUri,
result => {/* Check the send result */},
exception => {/* Log the error */}); 从上面的代码可以看出,发送Tile通知到Windows Phone应用多么简单,仅仅是创建一个新的TilePushNotificationMessage,并设置相关的属性,然后调用同步Send和异步SendAsync的方法即可。 发送Toast通知 下面的代码片段演示了如何使用Windows Phone的推送通知类库以同步和异步的方式发送Toast通知。 // Prepare a toast push notification message.
var toast =new ToastPushNotificationMessage
{
Title = “Title”, // Title to be displayed as the toast header.
Subtitle = “Sub Title” // Message to be displayed next to the toast header.
};
// Send the message synchronously.
try
{
var sendResult = toast.Send(phoneChannelUri);
// Check the send result.
}
catch (Exception ex)
{
// Log the error.
}
// Send the message asynchronously.
toast.SendAsync(
phoneChannelUri,
result => { /* Check the send result */ },
exception => { /* Log the error */ }); 发送Raw通知 下面的代码片段演示了如何使用Windows Phone的推送通知类库以同步和异步的方式发送Raw通知。 C# // Prepare a raw push notification message.
byte[] rawData = {};
var raw =new RawPushNotificationMessage
{
RawData = rawData, // Raw data to be sent with the message.
};
// Send the message synchronously.
try
{
var sendResult = raw.Send(phoneChannelUri);
// Check the send result.
}
catch (Exception ex)
{
// Log the error.
}
// Send the message asynchronously.
raw.SendAsync(
phoneChannelUri,
result => { /* Check the send result */ },
exception => { /* Log the error */ }); Windows Phone客户端设定启动推送通知 我们使用简单的Silverlight应用说明如何将推送通知消息发送到Windows Phone智能手机。 注册推送通知服务 为了接收推送通知消息,Windows Phone应用程序需要向微软推送通知服务MPNS发送注册请求,MPNS返回的Windows Phone智能手机的URI(统一资源标识符)。 在我们的示例中,推送通知PN功能封装在PushContext类。强烈建议您每次启动应用程序时将PN通道URI更新到Web Service,确保您的Web Service中保存的是智能手机最新的URI。 推送通知设置页面 每个Windows Phone应用,如果使用推送通知都必须允许用户设置推送通知功能的开启和关闭。 即程序开启推送通知PN通道时需要得到用户的许可,且用户也可以选择关闭推送通知PN通道。下面的画面(Project : WindowsPhone.Recipes.Push.Client File : Views/PushSettingControl.XAML)显示了示例应用程序的推送通知设定页面。 图 push setting Project : WindowsPhone.Recipes.Push.Client File : Views/PushSettingControl.XAML <UserControl x:Class="WindowsPhone.Recipes.Push.Client.Controls.PushSettingsControl"
xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:converters="clr-namespace:WindowsPhone.Recipes.Push.Client.Converters"
xmlns:d="schemas.microsoft.com/expression/blend/2008"
xmlns:mc="schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="640" d:DesignWidth="480">
<UserControl.Resources>
<converters:BoolBrushConverter x:Key="BoolBrushConverter"/>
<Style x:Key="DescTextStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="14"/>
<Setter Property="Foreground" Value="Silver"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="Margin" Value="16,-38,16,24"/>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<StackPanel>
<StackPanel>
<tk:ToggleSwitch Header="Push Notifications"
IsChecked="{Binding IsPushEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Turn on/off push notifications."/>
</StackPanel>
<Grid>
<StackPanel Margin="16,0,0,0">
<tk:ToggleSwitch Header="Tile Notifications"
IsChecked="{Binding IsTileEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Tile push notifications update the application's tile displayed in the Start Screen. The application must be pinned by the user first."/>
<tk:ToggleSwitch Header="Toast Notifications"
IsChecked="{Binding IsToastEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Toast push notifications are system-wide notifications that do not disrupt the user workflow or require intervention to resolve and are displayed in the top of the screen for ten seconds."/>
<tk:ToggleSwitch Header="Raw Notifications"
IsChecked="{Binding IsRawEnabled, Mode=TwoWay}"/>
<TextBlock Style="{StaticResource DescTextStyle}"
Text="Raw push notifications are used to send application specific information. The application must be running first."/>
</StackPanel>
<Border Background="{Binding IsPushEnabled, Converter={StaticResource BoolBrushConverter}}"/>
</Grid>
</StackPanel>
</Grid>
</UserControl> 当用户登录时,注册PN推送通知的通道。 Project: WindowsPhone.Recipes.Push.Client File: Views/ UserLoginView.xaml.cs privatevoid InternalLogin()
{
login.Visibility = Visibility.Collapsed;
progress.Visibility = Visibility.Visible;
var pushContext = PushContext.Current;
pushContext.Connect(c => RegisterClient(c.ChannelUri));
}
privatevoid RegisterClient(Uri channelUri)
{
// Register the URI with 3rd party web service.
try
{
var pushService =new PushServiceClient();
pushService.RegisterCompleted += (s, e) =>
{
pushService.CloseAsync();
Completed(e.Error);
};
pushService.RegisterAsync(UserName, channelUri);
}
catch (Exception ex)
{
Completed(ex);
}
} 向Web Service提交订阅,创建PN通道 Project: WindowsPhone.Recipes.Push.Client File: PushContext.cs publicvoid Connect(Action<HttpNotificationChannel> prepared)
{
if (IsConnected)
{
prepared(NotificationChannel);
return;
}
try
{
// First, try to pick up an existing channel.
NotificationChannel = HttpNotificationChannel.Find(ChannelName);
if (NotificationChannel ==null)
{
// Create new channel and subscribe events.
CreateChannel(prepared);
}
else
{
// Channel exists, no need to create a new one.
SubscribeToNotificationEvents();
PrepareChannel(prepared);
}
IsConnected =true;
}
catch (Exception ex)
{
OnError(ex);
}
}
publicvoid Disconnect()
{
if (!IsConnected)
{
return;
}
try
{
if (NotificationChannel !=null)
{
UnbindFromTileNotifications();
UnbindFromToastNotifications();
NotificationChannel.Close();
}
}
catch (Exception ex)
{
OnError(ex);
}
finally
{
NotificationChannel =null;
IsConnected =false;
}
} 创建PN通道的具体函数。 Project: WindowsPhone.Recipes.Push.Client File: PushContext.cs ///<summary>
/// Create channel, subscribe to channel events and open the channel.
///</summary>
privatevoid CreateChannel(Action<HttpNotificationChannel> prepared)
{
// Create a new channel.
NotificationChannel =new HttpNotificationChannel(ChannelName, ServiceName);
// Register to UriUpdated event. This occurs when channel successfully opens.
NotificationChannel.ChannelUriUpdated += (s, e) => Dispatcher.BeginInvoke(() => PrepareChannel(prepared));
SubscribeToNotificationEvents();
// Trying to Open the channel.
NotificationChannel.Open();
} 绑定和解除绑定Raw、Tile和Toast通知消息的函数。 Project: WindowsPhone.Recipes.Push.Client File: PushContext.cs private void BindToTileNotifications() { try { if (NotificationChannel != null && !NotificationChannel.IsShellTileBound) { var listOfAllowedDomains = new Collection<Uri>(AllowedDomains); NotificationChannel.BindToShellTile(listOfAllowedDomains); } } catch (Exception ex) { OnError(ex); } } private void BindToToastNotifications() { try { if (NotificationChannel != null && !NotificationChannel.IsShellToastBound) { NotificationChannel.BindToShellToast(); } } catch (Exception ex) { OnError(ex); } } private void UnbindFromTileNotifications() { try { if (NotificationChannel.IsShellTileBound) { NotificationChannel.UnbindToShellTile(); } } catch (Exception ex) { OnError(ex); } } private void UnbindFromToastNotifications() { try { if (NotificationChannel.IsShellToastBound) { NotificationChannel.UnbindToShellToast(); } } catch (Exception ex) { OnError(ex); } } Web Service设计推送通知功能 为了说明如何在Web Service设计推送通知服务功能,我们创建WPF应用程序Push Notifications Server,即Web Service,模拟第三方服务器。在WPF应用程序创建一个WCF服务,让Windows Phone应用订阅通知服务并与MPNS通讯。 WPF应用程序Push Notifications Server有五个选项卡(One-time、 Ask to Pin、 Custom Tile、Counter和Tile Scheduled),One-Time实现次性推送三种类型的通知消息;Counter演示计算器重置;Ask to Pin实现询问用户是否将应用程序固定显示在启动页面;Custom Tile实现定制Tile通知消息Tile Scheduled实现设定Tile更新计划表。下面的章节将详细讲述这五个选项卡的功能。 One-Time--一次性推送三种类型的通知消息 说明 One-Time选项卡是向注册用户提供最简单的推送模式,即一次性将三种类型的推送通知:Raw、Tile和Toast通知推送给Windows Phone。One-Time选项卡显示了三种类型通知的可设置的属性,以及MPNS的返回值类型。 操作
- 运行 WindowsPhone.Recipes.Push.Server 和WindowsPhone.Recipes.Push.Client projects (设置 WindowsPhone.Recipes.Push.Server为默认启动程序)。
- 在Windows Phone模拟器中以任意用户名登录。
- 在服务器端,选择"One Time"选项卡。
- 设置Raw、Tile和Toast消息内容,然后选择"Send"发送。
- URI必须能够访问到手机
- 图像的大小必须小于80KB
- 下载的时间不能超过60秒

