简体   繁体   中英

Send push notification over notification hub in azure mobile services

I'm trying to find out I way to send push notification over notifications hub in azure mobile services to windows phone users. I tried several ways like this. But there's no sent message.

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

Registration to services in wp I done like this:

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());
        });

This registration works fine when and I can send test notifications over debug in azure.

What I am doing wrong?

Beside that, how to add some tag in function for sending notification?

After some research I found right way to send push notifications to wp 8. There's great example and explanation here .

Basically here is function what makes notification and send it to tagged devices.

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);
    }});
}

I home this will help someone in future. And lots thanks to Geoff and his blog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM