你好,游客 登录 注册 搜索
背景:
阅读新闻

Windows Phone & Windows 8 Push Notification from Windows Azure

[日期:2013-08-18] 来源:Linux社区  作者:王博_Nick [字体:大 中 小]

在我们的服务中可以直接浏览到数据表中的数据.

image

 

当然这里也有 Win8 版本的demo code下载。

image

对于推送Windows Phone是这样的 客户端和之前没什么太多区别还是要注册手机推送通道.

在Manifest文件中标记推送

在手机App文件中添加以下代码

1. 引入命名空间

 
using Microsoft.Phone.Notification;
 

 

2. 添加以下代码

 
public static HttpNotificationChannel CurrentChannel { get; private set; }


private void AcquirePushChannel()
{
    CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");


if (CurrentChannel == null)
{
    CurrentChannel = new HttpNotificationChannel("MyPushChannel");
    CurrentChannel.Open();
    CurrentChannel.BindToShellTile();
}


}
 

 

3. 在Application_Launching事件方法中添加方法调用

 
AcquirePushChannel();
 

4.在TodoItem类中添加一个字段

 
[DataMember(Name = "channel")]
 public string Channel { get; set; }
 

 

5. 最后在MainPage页面中更改ButtonSave_Click事件响应代码

 
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
    var todoItem = new TodoItem { Text = TodoInput.Text, 
        Channel = App.CurrentChannel.ChannelUri.ToString() };
    InsertTodoItem(todoItem);
}
 

 

在 Windows Azure 云端我们要编辑下插入数据时的脚本代码

选择Data(数据) – Script (脚本) – Insert(插入)

更新代码如下:

 
function insert(item, user, request) {
    request.execute({
        success: function () {
            // Write to the response and then send the notification in the background
            request.respond();
            push.mpns.sendFlipTile(item.channel, {
                title: item.text
            }, {
                success: function (pushResponse) {
                    console.log("Sent push:", pushResponse);
                }
            });
        }
    });
}
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款