Windows (UWP)

Push Notifications (UWP)

The DevToDev.Messaging package necessary for notifications is available in the NuGet package manager.

1. NuGet Installation

DevToDev.Analytics.Uwp 2.0.1
DevToDev.Messaging.Uwp 2.0.1
Package Manager UI
Find the DevToDev.Messaging package using the package manager search engine and click Install. The latest version of the package is recommended.

2. Credentials

To integrate WNS, you need to get the Package SID and Application Secret Key from the Microsoft Partner Center and specify them in the devtodev push notification settings (Project -> Settings-> Push notifications):

3. Setup

For the correct package functioning, add handlers invoke to the Windows.UI.Xaml.Application class implementation.
sealed partial class App : Application
protected override void OnLaunched(LaunchActivatedEventArgs e)
// Your code...
protected override void OnActivated(IActivatedEventArgs args)
// Your code...
Besides, in the UI editor of the Package.appxmanifest file do the following:
  1. 1.
    Add Background Tasks to the Declarations tab and mark it as System Event. After that enter DevToDev.Background.ToastNotificationBackgroundTask to the Entry Point field.
  2. 2.
    Add Background Tasks to the Declarations tab and mark it as Push Notification. After that enter DevToDev.Background.RawNotificationBackgroundTask to the Entry Point field.

4. Initialization

For the DevToDev.Messaging package functioning you need to have the main DevToDev.Analytics package installed. Initialize the SDK before initializing messages. You can read about it in more detail in the SDK initialization section.
After the SDK has been initialized you can move to initializing messages. To do this, call the method:

5. Events

It is possible to listen to events from the DevToDev.Messaging package:
1. Push Token - a string that allows to identify the client on a remote server for sending him customized notifications. For listening the unique Push Token ID issue event, it is necessary to be subscribed to the event:
DTDMessaging.OnTokenReceived += token => { /* Your code... */ };
2. To track the errors related to the unique Push Token ID issue, it is necessary to be subscribed to the event:
DTDMessaging.OnTokenFailed += error => { /* Your code... */ };
Where error is a string value containing information about the error.
3. To handle incoming message data, it is necessary to be subscribed to the following event:
DTDMessaging.OnMessageReceived += messageData => { /* Your code... */ };
Where messageData belongs to the IDictionary<string, string> type and contains data sent from the server together with the message.
4. To handle notification activation events, it is necessary to be subscribed to the event:
DTDMessaging.OnMessageActivated += messageAction => { /* Your code with token. */ };
Where messageAction is DevToDev.Messaging.DTDMessageAction class instance:
/// <summary>
/// The class contains information about notification's action.
/// </summary>
public sealed class DTDMessageAction
/// <summary>
/// Action type.
/// Can be: Open, Url, Share, DeepLink.
/// </summary>
public DTDMessageActionType ActionType { get; }
/// <summary>
/// Action string.
/// </summary>
public string ActionString { get; }
/// <summary>
/// Activated button ID.
/// </summary>
public string ButtonId { get; }
/// <summary>
/// Activated button's text.
/// </summary>
public string ButtonText { get; }
/// <summary>
/// Notification data.
/// </summary>
public IReadOnlyDictionary<string, string> MessageData { get; }

6. Disabling

Call the method to turn notifications off:
Last modified 1mo ago