# Unreal Engine

## Plugin installation

The SDK can be found in the devtodev [GitHub repository](https://github.com/devtodev-analytics/unreal-sdk-2.0). Download the latest release of the [Source code (zip)](https://github.com/devtodev-analytics/unreal-sdk-2.0/releases/latest). Unzip the archive and copy the ***`DTDMessaging`*** folder to the ***Plugins*** folder of your project.

If you have a C++ type project, add **`DTDMessaging`** to the list of dependency names in the ***`<module_name>.Build.cs`*** file of the module in which you plan to use the plugin.

Example:

```cpp
PublicDependencyModuleNames.Add("DTDMessaging");
```

### Android

Add your ***`google-services.json`*** file to the project's root directory. It will be used to configure notifications during the project-building process.

### iOS

***In the case your Unreal Engine is built from GitHub source code:***

Enable notifications in the settings of your project: *`Edit → Project Settings → iOS → Enable Remote Notifications Support`*

***In the case your Unreal Engine is not built from GitHub source code:***

Add the parameter to the engine configuration file (*`<proj_dir>/Config/DefaultEngine.ini`*):

```cpp
// Some code/Script/IOSRuntimeSettings.IOSRuntimeSettings]
bEnableRemoteNotificationsSupport=True
```

## Data types

#### **`class UDTDMessagingBPLibrary`**

A class that implements analytic methods.

Header file:

```cpp
#include "DTDMessaging/Public/DTDMessagingBPLibrary.h"
```

#### **`enum class EDTDNotificationActionType : uint8`**

Notification action type

Header file:

```cpp
#include "DTDMessaging/Public/DTDNotificationActionType.h"
```

Values:

* ***`App = 0`*** - default value
* ***`Url = 1`*** - external link opening
* ***`Share = 2`*** - share contentc
* ***`DeepLink = 2`*** - an in-app link opening

#### **`struct FDTDNotification`**

Notification data container.

Header file:

```cpp
#include "DTDMessaging/Public/DTDNotification.h"
```

| Member             | Type                       | Description                        |
| ------------------ | -------------------------- | ---------------------------------- |
| **`ActionType`**   | EDTDNotificationActionType | Тип действия уведомления           |
| **`ActionString`** | FString                    | Идентификатор действия уведомления |
| **`Data`**         | TMap\<FString, FString>    | <p>Данные уведомления<br></p>      |

#### **`struct FDTDNotificationAction`**

Notification action data container.

Header file:

```cpp
#include "DTDMessaging/Public/DTDNotificationAction.h
```

| Member             | Type                       | Description                        |
| ------------------ | -------------------------- | ---------------------------------- |
| **`ActionType`**   | EDTDNotificationActionType | Тип действия уведомления           |
| **`ActionString`** | FString                    | Идентификатор действия уведомления |
| **`ButtonId`**     | FString                    | Идентификатор нажатой кнопки       |
| **`ButtonText`**   | FString                    | Текст нажатой кнопки               |
| **`ButtonIcon`**   | FString                    | Иконка нажатой кнопки              |
| **`IsBackground`** | bool                       | Режим открытия приложения кнопкой  |

#### **`enum class EDTDIOSNotificationOptions : uint8`**

{% hint style="warning" %}
iOS only
{% endhint %}

Push Notification display settings are **`Bitflags`** that are managed by the developer and allow for selecting the method of user notification. It can be altered by the end user.

By default, it has the value: **`Badge|Sound|Alert`**

Header file:

```cpp
#include "DTDMessaging/Public/DTDIOSNotificationOptions.h"
```

Values:

* ***`None = 0`*** - nothing
* ***`Badge = 1 << 0`*** - can display a badge on the app icon
* ***`Sound = 1 << 1`*** - can play a sound
* ***`Alert = 1 << 2`*** - can display an alert
* ***`CarPlay = 1 << 3`*** - can display a push notification on CarPlay
* ***`CriticalAlert = 1 << 4`*** - critical alerts can play a sound even if **Do Not Disturb** is enabled (critical alerts require a special entitlement issued by Apple). **Available from iOS 12 onwards.**
* ***`AppNotificationSettings = 1 << 5`*** - this option defines that the system should display a notification settings button in the app. **Available from iOS 12.0 onwards.**
* ***`Provisional = 1 << 6`*** - an option for sending provisional notifications to the Notification Center without interrupting functioning processes. **Available from iOS 12.0 onwards.**

{% hint style="info" %}
*Provisional* - Provisional push notifications are shown in the User Notification Center but not on the lock screen. This type of push notification doesn’t require an explicit opt-in from the user. You can start sending them as soon as the user installs and launches your app. However, the user can also explicitly enable/disable your notifications.
{% endhint %}

Use this setting to avoid the permission request on app launch because it is seen as intrusive, and most users opt out of it.

It’s also important that when using the Provisional setting, the user needs to go to Notification Center settings to allow explicit notifications.

#### **`Delegates`**

Header file:

```cpp
#include "DTDMessaging/Public/DTDMessagingDelegates.h"
```

Delegates:

```cpp
DECLARE_DELEGATE_OneParam(FDTDMessagingBoolParamsDelegate, bool);
DECLARE_DELEGATE_OneParam(FDTDMessagingStringParamsDelegate, const FString&);
DECLARE_DELEGATE_OneParam(FDTDMessagingNotificationParamsDelegate, const FDTDNotification&);
DECLARE_DELEGATE_TwoParams(FDTDMessagingNotificationActionParamsDelegate, const FDTDNotification&, const FDTDNotificationAction&);
```

## Initialization

Notification module initialization:

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FOjoY8QxcoaHguSbJYkHf%2Fimage.png?alt=media\&token=ce765822-3ad3-401e-a9d9-57a5c2d9d7df)

```cpp
UDTDMessagingBPLibrary::Initialize();
```

## Methods

#### **`SetAvailability`**

A method responsible for enabling/disabling push notifications. When the state changes, it sends an event that includes the **availability** status (**true** or **false**). The **availability** status flag is stored in the SDK.

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FePgP4wDMlFMSA8o3gbIs%2Fimage.png?alt=media\&token=a5784861-14ec-4170-97cf-883ddea25be5)

```cpp
UDTDMessagincgBPLibrary::SetAvailability(true);
```

#### **`GetAvailability`**

Get the current **`availability`** status flag (**true** or **false**):

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2Fgm5ZKuyvoxBJwv2rDJUl%2Fimage.png?alt=media\&token=92465aeb-884b-4245-81ba-866621f02a73)

| Argument       | Type                                                                                             | Description |
| -------------- | ------------------------------------------------------------------------------------------------ | ----------- |
| **`onResult`** | <ul><li>FDTDMessagingDynamicBoolParamsDelegate</li><li>FDTDMessagingBoolParamsDelegate</li></ul> | Callback    |

```cpp
auto onResult = new FDTDMessagingBoolParamsDelegate();
onResult->BindLambda([](bool value)
{
  // Your code...
});
UDTDMessagingBPLibrary::GetAvailability(*onResult);
```

#### **`GetToken`**

Get a current unique device ID used in the notification system:

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2F4IhjI233u70sOaVTjGmv%2Fimage.png?alt=media\&token=13282751-0f57-4149-8252-41372d38d441)

| Argument       | Type                                                                                                 | Description |
| -------------- | ---------------------------------------------------------------------------------------------------- | ----------- |
| **`onResult`** | <ul><li>FDTDMessagingDynamicStringParamsDelegate</li><li>FDTDMessagingStringParamsDelegate</li></ul> | Callback.   |

```cpp
auto onResult = new FDTDMessagingStringParamsDelegate();
onResult->BindLambda([](const FString& value)
{
  // Your code...
});
UDTDMessagingBPLibrary::GetToken(*onResult);
```

#### **`SetTokenListener`**

Set a token listener. The listener will be executed when the SDK updates a unique device ID in the notification system.

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FpkCEJK33xyOcEfHPBC7l%2Fimage.png?alt=media\&token=b72c22ab-f4b0-47de-8111-ddac2712fc9c)

| Argument       | Type                                                                                                 | Description |
| -------------- | ---------------------------------------------------------------------------------------------------- | ----------- |
| **`listener`** | <ul><li>FDTDMessagingDynamicStringParamsDelegate</li><li>FDTDMessagingStringParamsDelegate</li></ul> | Listener.   |

```cpp
auto listener = new FDTDMessagingStringParamsDelegate();
listener->BindLambda([](const FString& value)
{
  // Your code...
});
UDTDMessagingBPLibrary::SetTokenListener(*listener);
```

#### **`SetTokenErrorListener`**

Set a listener for errors in token reception. The listener will be executed when an error occurs while the SDK updates a unique device ID in the notification system.

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FJroJ6HTWElAlKGQBfsVz%2Fimage.png?alt=media\&token=40502494-de8c-4ea9-9764-e08d54baed4e)

| Argument       | Type                                                                                                 | Description |
| -------------- | ---------------------------------------------------------------------------------------------------- | ----------- |
| **`listener`** | <ul><li>FDTDMessagingDynamicStringParamsDelegate</li><li>FDTDMessagingStringParamsDelegate</li></ul> | Listener.   |

```cpp
auto listener = new FDTDMessagingStringParamsDelegate();
listener->BindLambda([](const FString& value)
{
  // Your code...
});
UDTDMessagingBPLibrary::SetTokenErrorListener(*listener);
```

#### **`SetNotificationReceiveListener`**

Set a listener for notification reception. The listener will be executed when the SDK receives a notification.

<img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FpC5CbfMjcsVriVxIl1Gl%2Fimage.png?alt=media&#x26;token=70a050ed-c7b3-413c-a1f2-73d0df05cd7c" alt="" data-size="original">

| Argument       | Type                                                                                                             | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| **`listener`** | <ul><li>FDTDMessagingDynamicNotificationParamsDelegate</li><li>FDTDMessagingNotificationParamsDelegate</li></ul> | Listener.   |

```cpp
auto listener = new FDTDMessagingNotificationParamsDelegate();
listener->BindLambda([](const FDTDNotification& notification)
{
  // Your code...
});
UDTDMessagingBPLibrary::SetNotificationReceiveListener(*listener);
```

#### **`SetInvisibleNotificationReceiveListener`**

Set a listener for invisible notification reception. The listener will be executed when the SDK receives an invisible notification.

![](https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FdGSfhMuS8EYl5gByBTnP%2Fimage.png?alt=media\&token=00c3c925-99fb-4c7d-983d-0a8d1bdf047e)

| Argument       | Type                                                                                                             | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| **`listener`** | <ul><li>FDTDMessagingDynamicNotificationParamsDelegate</li><li>FDTDMessagingNotificationParamsDelegate</li></ul> | Listener.   |

```cpp
auto listener = new FDTDMessagingNotificationParamsDelegate();
listener->BindLambda([](const FDTDNotification& notification)
{
  // Your code...
});
UDTDMessagingBPLibrary::SetInvisibleNotificationReceiveListener(*listener);
```

#### **`SetNotificationActionListener`**

Set a listener for notification activation. The listener will be executed when the notification gets activated.

<img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2Fsrx5YjGFB2wKmro9ydio%2Fimage.png?alt=media&#x26;token=dd2fcc1f-e077-4674-8030-10e10b7edbd7" alt="" data-size="original">

| Argument       | Type                                                                                                                         | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------- | ----------- |
| **`listener`** | <ul><li>FDTDMessagingDynamicNotificationActionParamsDelegate</li><li>FDTDMessagingNotificationActionParamsDelegate</li></ul> | Listener.   |

```cpp
auto listener = new FDTDMessagingNotificationActionParamsDelegate();
listener->BindLambda([](const FDTDNotification& notification, const FDTDNotificationAction& action)
{
  // Your code...
});
UDTDMessagingBPLibrary::SetNotificationActionListener(*listener);
```

#### **`IOSSetNotificationOptions`**

{% hint style="warning" %}
iOS only
{% endhint %}

Set notification parameters.

<img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FPIHegNH5fyIXOVaUmDAa%2Fimage.png?alt=media&#x26;token=7b57ec9d-04b8-4213-b8ef-efe0b285af9d" alt="" data-size="original">

| Argument      | Type  | Description |
| ------------- | ----- | ----------- |
| **`options`** | int32 | Options.    |

{% hint style="warning" %}
An **int32** type value is used as an argument of this method. However, this argument should be calculated by using enumerators of **`EDTDIOSNotificationOptions`** and bitwise OR operator.
{% endhint %}

```cpp
int32 options = EDTDIOSNotificationOptions::Badge |
  EDTDIOSNotificationOptions::Sound |
  EDTDIOSNotificationOptions::Alert;
UDTDMessagingBPLibrary::IOSSetNotificationOptions(options);
```
