Implementing the SDK

Implementing Mobile SDK for IOS requires the steps below

Setting Integration Key

Integration Key is genereted by CDMP Platform while defining application. It is a hash string which contains information about application.

At the beginning of your application cycle you must set Integration Key.

To set integration key SDK Provides Dengage.setIntegrationKey(key: String) method.

Call this method at the begining of your application life cycle.

Recommendation : Use it on AppDelegate

Dengage.setIntegrationKey(key: String)

Initialization with Launch Options

After setting Integration Key, to use SDK features, Dengage.initWithLaunchOptions(withLaunchOptions: [UIApplication.LaunchOptionsKey: Any]?,badgeCountReset: Bool?) function must be called.

Parameters:

  • withLaunchOptions: [UIApplication.LaunchOptionsKey: Any]?: Pass didFinishLaunchingWithOptions params
  • badgeCountReset : bool If you want to reset (clear) badge icon on your notifications set this option to true

Following sample shows how to do that in your AppDelegate.m file: Sample: In the AppDelegate.m

import Dengage_Framework

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, REFrostedViewControllerDelegate {
    // STEP 1: setting integration key
    let integrationKey = ""
    Dengage.setIntegrationKey(key: integrationKey)

    // STEP 2: setting initWithLauchOptions
    Dengage.initWithLaunchOptions(withLaunchOptions: launchOptions, badgeCountReset: false)
}

Subscription

Subscription is self-managed by SDK.

Definition: Subscription is a process which is triggered by sending subscription event to Dengage. It contains necessary informations about application to send push notifications to clients.

Subcription cycle starts with Prompting user permission. SDK will automaticlly send subscription events under these circumstances;

  • Initialization
  • Setting Contact key
  • Setting Token
  • Setting User Permission (if you have manual management of permission)

Asking User Permission for Notification

Note: Android doesn’t require to ask for push notifications explicitly. Therefore, you can only ask for push notification’s permissions on iOS.

IOS uses shared UNUserNotificationCenter by itself while asking user to send notification. Dengage SDK manager uses UNUserNotificationCenter to ask permission as well.

Referrer:Apple Docs

If in your application, you want to get UserNotification permissions explicitly, you can do by calling one of the following methods:

// At the top import
import Dengage_Framework

Dengage.promptForPushNotifications()

//OR

Dengage.promptForPushNotifications(callback: (Bool) -> Void)

Setting Contact Key

Contact Key represents a value that has a relation with Devices and Contacts. There are two types of devices. Anonymous Devices and Contact Devices. Contact Devices contains Contact Key

To track devices by their contacts you need to set the contact key on SDK.

Recommended Usage: You should call this method, if you have user information. You should call in every app open and on login, logout pages.

// import statement
import Dengage_Framework

Dengage.setContactKey(contactKey: String)

// You may need getting current contact key from SDK. In that case you can use getContactKey
let currentContact = Dengage.getContactKey()

Manual Management of Tokens

If you need to get the current token or if you are managing the token subscription process manually, you can use setToken and getToken functions.

Push tokens can be set by Dengage.setToken(token: String)method.

Definition : Push token is a data type which will be provided by APNS. By using token, CDMP can push notifications to client application.

promptForPushNotifications method will trigger func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) method for push token which has to be set by a method.

func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        var token = "";
        if #available(iOS 13.0, *){
            
            token = deviceToken.map { String(format: "%02x", $0) }.joined()
        }
        else{
            let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
            token = tokenParts.joined()
        }

        // set token to SDK
        Dengage.setToken(token: token)
    }

Also you can use getToken function for getting current token from D·engage SDK.

// At the top import
import Dengage_Framework

let currentToken = Dengage.getToken()

In order to disable the automatic registerForRemoteNotifications call to the operating system, use the following code. In this case, you should be doing it in the application code. Add this code before initWithLaunchOptions

Dengage.registerForRemoteNotifications(enable: false) // default value: true

User Permission Management (optional)

If you manage your own user permission states on your application you may send user permission by using setUserPermission method.

// At the top import
import Dengage_Framework

Dengage.setUserPermission(permission: (Bool))

// For getting last permission set by user
let currentUser = \(Dengage.getPermission())

Logging

SDK can provide logs for debuging. It displays queries and payloads which are sent to REST API’s.

To validate your inputs you can enable SDK’s log by a method.

// isVisible is Boolean. By default isVisible set to false.
Dengage.setLogStatus(isVisible: bool)

Handling Notification Action Callback

SDK provides a method if you want to get and parse payload manually for custom parameters or etc.

//Method:

handleNotificationActionBlock(callback: @escaping(_ notificationResponse: UNNotificationResponse) -> Void)


//Sample:

Dengage.HandleNotificationActionBlock { (notificationResponse) in
let messageDetails = notificationResponse.notification.request.content.userInfo["messageDetails"] as! String;
let messageId = notificationResponse.notification.request.content.userInfo["messageId"] as! Int;
// do something with payload
																			}

DeepLinking

SDK supports URL schema deeplink. If target url has a valid link, it will redirect to the related link.

disableOpenURL

If the link opens in both safari and application, you can prevent it from opening in safari by using the method below.

Dengage.disableOpenURL = true