0

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

我做错了什么?

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

4

1 回答 1

0

经过一些研究,我找到了将推送通知发送到 wp 8 的正确方法。这里有很好的示例和解释

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

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 和他的博客。

于 2013-12-04T21:41:00.493 回答