本文介绍了如何使用Windows Azure的Mobile Service发送推送信息Windows商店应用程序。
建立一个Mobile Service的同时Azure会自动创建一个数据库。推送消息就是在对数据库这些表的插入、删除操作的同时,通过脚本语言发送
先来明确一下大体上要做哪些步骤:
1.注册Windows商店应用的推送通知,配置Mobile Service。
2.通过代码在应用中添加推送通知。
3.在Windows Azure控制中心更新脚本语言来发送推送。
4.添加数据,并接收WNS推送。
第一步:注册Windows商店应用的推送通知,配置Mobile Service
1.在Windows Azure上新建一个Mobile Service。
2.新建一个商店应用并关联到应用商店,这里我们可以用MobileService门户上给的样例程序。按照步骤来获取。
3.关联Windows商店应用到Mobile Service。方法和上一讲的关联一样,这里不多说了。
第二步:通过代码在应用中添加推送通知
1.在App.cs中添加下列引用
using
Windows.Networking.PushNotifications;
2.接着添加如下代码
public static PushNotificationChannel CurrentChannel { get; private set; }
private async void AcquirePushChannel()
{
CurrentChannel =
await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
}
3.在OnLanched()函数中添加
AcquirePushChannel();
4.在MainPage.xaml.cs中有一个TodoItem的类,在类中添加
[JsonProperty(PropertyName = "channel")]
public string Channel { get; set; }
5.修改MainPage.xaml.cs中的ButtonSave_Click函数
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
var todoItem = new TodoItem { Text = TextInput.Text, Channel = App.CurrentChannel.Uri };
InsertTodoItem(todoItem);
}
6.不要忘了让你的程序支持Toast推送
第三步:在Windows Azure控制中心更新脚本语言来发送推送。
1.点击服务上方的数据,然后点击TodoItem,其实这个TodoItem就是数据库中的表。
2.修改脚本(script),我们这里仅仅对表的插入操作进行修改。
3.将上边的脚本改为
function insert(item, user, request) {
request.execute({
success: function() {
// Write to the response and then send the notification in the background
request.respond();
push.wns.sendToastText04(item.channel, {
text1: item.text
}, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse);
}
});
}
});
}
第四步:添加数据,并接收WNS推送。
分享到:
相关推荐
《云计算(第二版)》教材配套课件[PPT] 第四章 微软云计算Windows Azure(2).ppt
将带来Windows Azure平台的功能以及开发的方式等各式各样的信息,帮助您了解微软的云计算平台以及相关技术,或是评估微软的Windows Azure平台能力,以及如何在Windows Azure上开发应用程序的知识和技术。 全书共12章...
《实战windows azure:微软云计算平台技术详解》来自于微软 windows azure mvp 的技术实践和心得体会,主要包括windows azure 平台的基础知识、使用方法、功能特点以及如何基于windows azure 平台设计高可靠、可扩展...
QCon 2009 beijing全球企业开发大会ppt: ...6.微软云计算平台-Windows Azure架构探析 ...通过这一个主题,您将会了解微软云计算策略,Windows Azure平台包含的内容以及如何能帮助企业构建云端应用,如何开发等。
《实战Windows Azure:微软云计算平台技术详解》来自于微软 Windows Azure MVP 的技术实践和心得体会,主要包括Windows Azure 平台的基础知识、使用方法、功能特点以及如何基于Windows Azure 平台设计高可靠、可扩展...
实战 Windows Azure:微软云计算平台技术详解
《云计算(第二版)》教材配套课件[PPT] 第四章 微软云计算Windows Azure(1).ppt
QCon 2009 beijing全球企业开发大会ppt:(共25个资料,若要下载其他部分,点击 标签“QCon”...通过这一个主题,您将会了解微软云计算策略,Windows Azure平台包含的内容以及如何能帮助企业构建云端应用,如何开发等。
实战WindowsAzure:微软云计算平台技术详解(目录)实战WindowsAzure:微软云计算平台技术详解(目录)
《实战windows azure 微软云计算平台技术详解》。
第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第5章 Hadoop 2.0 主流开源云架构(二) 第5...
第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第5章 Hadoop 2.0 主流开源云架构(二) 第5...
第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第5章 Hadoop 2.0 主流开源云架构(二) 第5...
微软Windows Azure云计算平台
第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第5章 Hadoop 2.0 主流开源云架构(二) 第5...
微软的云计算平台AZURE
本书特别为云计算的入门读者编写,对于云计算技术人员、技术战略分析人员和爱好者也有重要的参考价值,还可供高等院校云计算和并行计算的研究者和同学作为参考资料及教材使用。
Windows Azure 表存储:不同于传统数据库.pdf
深入浅出介绍微软Windows Azure云计算平台