iOS

iOS Integration

Platform integration

Creating a Universal Push Notification Client SSL Certificate

You use Member Center to generate a push notification client SSL certificate that allows your notification server to connect to the APNs. Each App ID is required to have its own client SSL certificate. The client SSL certificate Member Center generates is a universal certificate that allows your app to connect to both the development and production environments.

Only a team agent or admin can generate Apple Push Notification service SSL certificates.

To generate a universal client SSL certificate

  1. In Certificates, Identifiers & Profiles, select Certificates.

  2. Choose an App ID from the App ID pop-up menu, and click Continue. Choose the explicit App ID that matches your bundle ID.

  3. Create a certificate request on your Mac.

  4. Click Choose File.

  5. In the dialog that appears, select the certificate request file (with a .certSigningRequest extension), and click Choose File.

  6. Click Generate.

Follow these steps to export the certificate from Apple web-site to the P12-file:

  1. Open "Keychain access" application

  2. If the certificate hasn't been added to keychain access yet, choose "File" → "Import". Find the certificate file (CER-file) provided by Apple

  3. Choose "Keys" section in "Keychain access" application

  4. Choose a personal key associated with your iPhone developer certificate. Personal key is identified by open certificate associated with it "iPhone developer: ". Choose "File" → Export objects. Save key as .p12

  5. You'll be suggested to create a password which is used when you need to import the key to another computer

Upload the certificate to the site

Upload the .p12-file into Integration section of application settings panel (Settings -> Push Notifications):

Module initialization

1. For the Messaging module to function you need the basic Analytics package. Before the notification initialization, you need to initialize the SDK. More about it you can read here: Unity Integration.

2. After the DTDAnalytics initialization block call the StartNotificationService method to activate the Messaging module:

DTDMessaging.IOS.StartNotificationService();

Optional:

You can listen to basic notification module events. To do this, create a class that implements the IDTDPushListener interface and pass it to the DTDMessaging.IOS.SetPushListener method.

Example:

public class MyPushListener : IDTDPushListener
{
    public void OnPushServiceRegistrationSuccessful(string deviceId)
    {
        Debug.Log(deviceId);
    }

    public void OnPushServiceRegistrationFailed(string error)
    {
        Debug.Log(error);

    }

    public void OnPushNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnInvisibleNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnPushNotificationOpened(DTDPushMessage pushMessage, DTDActionButton actionButton)
    {
        Debug.Log(pushMessage.ToString());
        Debug.Log(actionButton.ToString());
    }
}

You can specify the necessary display options using the DTDMessaging.IOS.SetNotificationOptions method.

Example:

DTDMessaging.IOS.SetNotificationOptions(DTDNotificationOptions.Alert | DTDNotificationOptions.Badge | DTDNotificationOptions.Sound);

A complete example of the notification module initialization:

public class MyPushListener : IDTDPushListener
{
    public void OnPushServiceRegistrationSuccessful(string deviceId)
    {
        Debug.Log(deviceId);
    }

    public void OnPushServiceRegistrationFailed(string error)
    {
        Debug.Log(error);

    }

    public void OnPushNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnInvisibleNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnPushNotificationOpened(DTDPushMessage pushMessage, DTDActionButton actionButton)
    {
        Debug.Log(pushMessage.ToString());
        Debug.Log(actionButton.ToString());
    }
}

public class NotificationExample : MonoBehaviour
{
    private const string APP_KEY = "***************"
    void Start()
    {
        DTDAnalytics.Initialize(APP_KEY);
        DTDMessaging.IOS.SetNotificationOptions(DTDNotificationOptions.Alert | DTDNotificationOptions.Badge | DTDNotificationOptions.Sound);
        DTDMessaging.IOS.SetPushListener(new PushListener());
        DTDMessaging.IOS.StartNotificationService();
    }
}

External interface of the DTDMessaging module for iOS platform

MethodesDescription

void DTDMessaging.IOS.StartPushService()

The method responsible for push notification activation:

  • Requests user permission to receive push notifications

  • Sends push token and current state isAllowed

void DTDMessaging.IOS.GetToken(Action<string> onGetToken)

The method that returns current push token to onGetToken callback

DTDMessaging.IOS.SetPushListener(IDTDPushListener listener)

The method for assigning a push notification event listener

void DTDMessaging.IOS.PushNotificationsOptions(uint options)

options is responsible for setting up the display of Push Notifications. It is set by the developer to select the method of notifying the user. It can be changed by the end-user.

By default, it has the value:

[.DTDNotificationOptionBadge, .DTDNotificationOptionSound, .DTDNotificationOptionAlert]

void DTDMessaging.IOS.PushIsAllowed (bool isAllowed )

The method is responsible for enabling / disabling the ability to send a push notification to the user from devtodev.

void DTDMessaging.IOS.GetPushState(Action<bool> onGetPushState)

The method that returns the push module state to onGetPushState callback

IDTDPushListener interface

Delegate methodDescription

void OnPushServiceRegistrationSuccessful (string deviceId);

The method is called if a push token is successfully received, represented by a string.

void OnPushServiceRegistrationFailed (string error);

The method is called if at the time of receiving a pushToken errors occur. It passes the text of the error that occurred

void OnInvisibleNotificationReceived (DTDPushMessage message);

The method is called when an invisible remote push notification is received. The DTDPushMessage object is passed

void OnPushNotificationReceived (DTDPushMessage message);

The method is called when a remote push notification is received while the application runs in the Foreground state. The DTDPushMessage object is passed.

void OnPushNotificationOpened (DTDPushMessage pushMessage, DTDActionButton actionButton);

The method is called when the end-user opens a remote push notification. The DTDPushMessage object and the optional DTDActionButton object are passed.

Class for receiving Notification data(DTDPushMessage). Main class properties

PropertyDescription

IDictionary<string,string> GetData():

Complete information passed with the push notification.

DTDActionType ActionType:

The property that returns the value of enum’s DTDActionType.

Possible values:

App - app open

Url - external link open

Share - share content

Deeplink - open a link that leads straight to a specific in-app location

string ActionString

The property that returns an optional action identifier

IDictionary<string,string> AdditionalData()

Additional data sent to push notification

Class for handling buttons clicked in the notification (DTDActionButton)

PropertyDescription

DTDActionType ActionType

The property that returns the value of enum’s DTDActionType.

Possible values:

App - app open

Url - external link open

Share - share content

Deeplink - open a link that leads straight to a specific in-app location

string ActionString

The property that returns an optional action identifier

string ButtonId

The property that returns the ID of the clicked button

string ButtonText

The property that returns the text of the clicked button

DTDNotificationOptions

It is an OptionSet used for push notification authorization and configuration interaction with users.

Attention: The user can change the allowed parameters in the notification settings at any time.

Possible values:

  • DTDNotificationOptionBadge - an option for displaying a badge on the application icon

  • DTDNotificationOptionSound - an option for playing sound

  • DTDNotificationOptionAlert - an option for displaying an alert

  • DTDNotificationOptionCarPlay - an option for showing a push notification in CarPlay DTDNotificationOptionCriticalAlert - an option for playing sound for critical alerts regardless of whether “do not disturb” is on or not. (Critical alerts require special permission from Apple). Available from iOS 12.0 onwards

  • DTDNotificationOptionProvidesSettings - an option for indicating that the system should show a notification settings button in the application. Available from iOS 12.0 onwards

  • DTDNotificationOptionProvisional - an option for sending provisional notifications to the Notification Center without interrupting functioning processes. Available from iOS 12.0 onwards

  • DTDNotificationOptionAnnunciation - an option for Siri to automatically read messages through AirPods. Available from iOS 13.0 onwards

Attention: DTDNotificationOptionProvisional - 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.

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 DTDNotificationOptionProvisional setting, the user needs to go to Notification Center settings to allow explicit notifications.

XCODE build

After the build, open the signing and capabilities tab in the XCode project settings and add "Push Notifications" and "Background Modes" (tick the box against Remote notifications).

Notification with Attachments

The framework provides support for iOS 10+ notification attachments, such as images, animated gifs, and video. In order to take advantage of this functionality, you will need to create a notification service extension alongside your main application. Create a new iOS target in Xcode (File -> New -> Target) and select the Notification Service Extension type. ​In the Member Center, a Push Notifications service will appear as Configurable (not Enabled) until you create a client SSL certificate.

The framework supports notification attachments: images, audio, and video. To enable the functionality, you need to complete several steps:

  • Create a new iOS target in Xcode (File -> New -> Target) and select the Notification Service Extension

  • Set language to ‘Swift’

  • In the next window, click ‘Activate’

  • In the ‘Build Settings’ tap, change 'Architectures’ to ‘Standard Architecture (arm64, armv7)

  • Open the ‘Frameworks’ folder in your project, find the ‘DTDMessagingUnity’ framework and tick the box of your target in the ‘Target Membership’ section

  • In the NotificationService class (in the folder named after your target), replace the code with the following:

import UserNotifications
import DTDMessagingUnity

class NotificationService: DTDMediaAttachmentExtension {

}

Custom sounds

To use custom sounds for push notifications, you need to copy the necessary sound files to the Libraries folder of your Xcode project. You can read more about supported formats here.

When creating a push company, it is important to specify the full name of the sound with file extension (for example, sound.wav).

Last updated