Question

I'm sending push notification using azure notification hub by node js script. I can send and receive push notification. I don't know how to retrieve data. I'm sending push as follows:-

function sendNotifications(pushMessage) {
    console.log('inside sendNotifications');
    var hub = azure.createNotificationHubService('hubname','connection string');

    hub.mpns.sendToast(
        null,
        {
            text1: pushMessage,
            text2: 'some data'
        },
        function (error)
        {
            if (!error)
            {
                //message send successfully
                console.log("mpns.sendToast push success: "+error);
                RESPONSE.send(statusCodes.OK, { ResponseMessage : 'mpns.sendToast message success' });
            }
            else
            {
                // msg failed to send
                console.log("errro error.shouldDeleteChannel: "+error);
                RESPONSE.send(statusCodes.OK, { ResponseMessage :'mpns.sendToast message error '+error });
            }
        });
}

I would like to receive the text1 and text2 in my receiving application. Could you inform me how to do it? Or do I need to send push notification differently if I want to push some data? How to push data together with push nitrification? Also how large data I can push?

Était-ce utile?

La solution

If your app is already open when the toast notification is received, the following event handler can get the parameters of the notification (for example e.Collection[wp:Text1] will return the title of the toast) :

void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
    StringBuilder message = new StringBuilder();
    string relativeUri = string.Empty;

    message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

    // Parse out the information that was part of the message.
    foreach (string key in e.Collection.Keys)
    {
        message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);

        if (string.Compare(
            key,
            "wp:Param",
            System.Globalization.CultureInfo.InvariantCulture,
            System.Globalization.CompareOptions.IgnoreCase) == 0)
        {
            relativeUri = e.Collection[key];
        }
    }

    // Display a dialog of all the fields in the toast.
    Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString()));

}

If your app is opened by clicking the toast notification, you can implement the following method in the page where your app is opened. You can access the parameters passed in the query string of the wp:Param parameter of the toast notification. I'm not sure how to get Text1 and Text2 in this method.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    //  If we navigated to this page
    // from the MainPage, the DefaultTitle parameter will be "FromMain".  If we navigated here
    // when the secondary Tile was tapped, the parameter will be "FromTile".
    textBlockFrom.Text = "Navigated here from " + this.NavigationContext.QueryString["NavigatedFrom"];

}

Code samples were taken from here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top