# Windows (UWP)

## Push Notifications (UWP)

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

### 1. NuGet Installation

{% embed url="<https://www.nuget.org/packages/DevToDev.Analytics.Uwp/>" %}

{% embed url="<https://www.nuget.org/packages/DevToDev.Messaging.Uwp/>" %}

**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](https://partner.microsoft.com/en-us/dashboard/home) and specify them in the devtodev push notification settings (Project -> Settings-> Push notifications):

![](/files/DLCSY7rQHycVNBfEE4YQ)

![](/files/10U3QFb39qFPFqedjAmS)

![](/files/ATo820UZHzGVu1eT2lgS)

![](/files/6zulZMLH95MGPBvN9eIG)

### 3. Setup

For the correct package functioning, add handlers invoke to the **`Windows.UI.Xaml.Application`** class implementation.

```csharp
sealed partial class App : Application
{
  protected override void OnLaunched(LaunchActivatedEventArgs e)
  {
    // Your code...
    DTDMessaging.HandleActivatedEvent(e);
  }
  
  protected override void OnActivated(IActivatedEventArgs args)
  {
      // Your code...
      DTDMessaging.HandleActivatedEvent(args);
  }
}
```

Besides, in the UI editor of the ***Package.appxmanifest*** file do the following:

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. 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](https://docs.devtodev.com/integration/integration-of-sdk-v2/push-notifications/pages/-MkwFB-F75tzaUO1ocsq#id-2.-sdk-initialization).

After the SDK has been initialized you can move to initializing messages. To do this, call the method:

```csharp
DTDMessaging.SetMessagingEnabling(true);
```

### 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:

```csharp
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:

```csharp
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:

```csharp
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:

```csharp
DTDMessaging.OnMessageActivated += messageAction => { /* Your code with token. */ };
```

Where **`messageAction`** is **`DevToDev.Messaging.DTDMessageAction`** class instance:

```csharp
/// <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:

```csharp
DTDMessaging.SetMessagingEnabling(false);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devtodev.com/integration/integration-of-sdk-v2/push-notifications/windows-uwp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
