【问题标题】:Send push notification over notification hub in azure mobile services通过 Azure 移动服务中的通知中心发送推送通知
【发布时间】:2013-12-10 16:53:19
【问题描述】:

我正在尝试找出通过 Azure 移动服务中的通知中心向 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 中的调试发送测试通知时,此注册工作正常。

我做错了什么?

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

【问题讨论】:

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


    【解决方案1】:

    经过一番研究,我找到了向 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 和他的博客。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 2016-04-24
      • 2022-01-12
      • 2018-04-28
      相关资源
      最近更新 更多