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. Click the Add button (+)

  3. Under Production, select the “Apple Push Notification service SSL (Sandbox & Production)” checkbox, and click Continue.

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

  5. Create a certificate request on your Mac.

  6. Click Choose File.

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

  8. Click Generate.

  9. Click Download.

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

IDTDPushListener interface

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

Class for handling buttons clicked in the notification (DTDActionButton)

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