简体   繁体   中英

Is there a way to enable a push notification so that when a user clicks it, it brings them to a page related to what the notification showed?

My Asp.net MVC sends push notifications to my WP8 app. The notifications show the names of specific data. For instance, on a specific date, it will send the name of a record from my Sql Server Database, say "aName". So the notification appears as "aName" that day. The next day it does the same thing with a different name, "bName".

I want the user to be able to click the notification and have it bring them to a details page where it shows the data that is related to the name that appeared on the notification when they clicked it. What would be the best way in your opinion?

You can send parameters to your app with the toast notification. Your app can then check this parameter and show a specific page with some details. In our toasts we send an uri with parameters like following example:

var toastmsg = String.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast>" +
    "<wp:Text1>{0}</wp:Text1>" +
    "<wp:Text2>{1}</wp:Text2>" +
    "<wp:Param>{2}</wp:Param>" +
    "</wp:Toast>" +
    "</wp:Notification>", "title", "message", "myuri");

Example for the uri: /mynotification/myaction?param=aName

In your WindowsPhone app you can define a custom UriMapper like following snippet:

public class MyCustomUriMapper : UriMapperBase
{
    public override Uri MapUri(Uri uri)
    {
        var tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

        if (tempUri.StartsWith("/mynotification"))
        {
            // Check your uri param and redirect to a page with uri
            // or set some properties to check in your MainPage
        }

    }
}

Then in your App.xaml.cs in the constructor set the UriMapper:

// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = new MyCustomUriMapper();

Thats how we navigate in our app with the notifications. We dont want to set the Page-Xaml-FileName in the notification-content, because they can change over time.

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