在天蓝色移动服务中通过通知中心发送推送通知

时间:2013-11-25 19:50:59

标签: c# azure push-notification azure-mobile-services azure-notificationhub

我正试图找出通过天蓝色移动服务中的通知中心向Windows Phone用户发送推送通知的方法。我尝试了几种这样的方法。但是没有发送消息。

hub.mpns.sendToast("PushChannel", template, sendComplete);

在wp中注册服务我是这样做的:

var channel = HttpNotificationChannel.Find("cQuestPushChannel");
if (channel == null){
    channel = new HttpNotificationChannel("cQuestPushChannel");
    channel.Open();
    channel.BindToShellToast();
}

string[] tagsToSubscribeTo = { "xxx" };

channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
        {
            var hub = new NotificationHub("***", "***");
            await hub.RegisterNativeAsync(args.ChannelUri.ToString());
        });

此注册工作正常,我可以通过azure中的调试发送测试通知。

我做错了什么?

除此之外,如何在函数中添加一些标签来发送通知?

1 个答案:

答案 0 :(得分:0)

经过一些研究后,我找到了向wp 8发送推送通知的正确方法。有很好的例子和解释here

基本上这里是通知的功能,并将其发送到标记设备。

function sendToastHubMpns(text1, text2, tagExpression)
{
    var azure = require("azure");
    var notificationHubService = azure.createNotificationHubService('hub_name', 
'hub_key');

    var toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<wp:Notification xmlns:wp=\"WPNotification\">" +
        "<wp:Toast>" +
            "<wp:Text1>" + text1 + "</wp:Text1>" +
            "<wp:Text2>" + text2 + "</wp:Text2>" +
        "</wp:Toast> " +
    "</wp:Notification>";

    notificationHubService.mpns.send(tagExpression, toast, "toast", 2, function(error) {
    if (error) {
        console.error(error);
    }});
}

我回家这将有助于将来的某个人。非常感谢Geoff和他的博客。

相关问题