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

Windows Phone & Windows 8 Push Notification from Windows Azure

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

1. 使用命名空间

 
using Windows.Networking.PushNotifications;
 

 

2. App文件中添加代码

 
public static PushNotificationChannel CurrentChannel { get; private set; }


private async void AcquirePushChannel()
{
        CurrentChannel =  
            await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
}
 

 

3. OnLaunched 事件中添加

 
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 = TextInput.Text, Channel = App.CurrentChannel.Uri };
        InsertTodoItem(todoItem);
    }
 

另外我这里更新Windows Azure插入数据脚本。我这里是插入数据时推送所有设备信息(Win8 & windows Phone 土司消息)

 
function insert(item1, user, request) {

    request.execute(); 
    
    var permissionsTable = tables.getTable('todoitem'); 
    
permissionsTable.where(function(){ 
    return this.channel !== null 
}).read({ success: function(channels) { 
     console.log("read data:", channels.length ); 
     
     var pushString= 'Hello'; 
     
       channels.forEach(function(item) { 
           if(item.iswin8data === true){ 
     push.wns.sendToastText04(item.channel, { 
                text1: item1.text 
            }, { 
                success: function(pushResponse) { 
                    console.log("Sent push:", pushResponse); 
                } 
            }); 
           }else{ 
                   push.mpns.sendToast(item.channel, { 
        text1: item1.text, 
        test2: new Date().toISOString().replace(/T/, ' ').replace(/\..+/, ''), 
        param: '/Page2.xaml?NavigatedFrom=Toast Notification' 
    }, { 
       success: function (pushResponse) { 
                    console.log("Sent toast push sucess:",pushResponse+" "+item.channel); 
                }, 
                   error: function (failedResponse){ 
                    console.log("Sent toast push fail:", failedResponse); 
                } 
    }); 
           } 
                
             }); 
             
     
}});

}
 

image

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

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