Implementing the SDK

Implementing Mobile SDK for IOS requires the steps below

Setting Integration Key

Integration Key is generated by CDMP Platform while defining application. It is a hash string that contains information about the application.

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

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

Recommendation: Use it on AppDelegate

Dengage.start(apiKey: 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

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, REFrostedViewControllerDelegate {
   Dengage.start(apiKey: “”, application: application
, launchOptions: launchOptions
, dengageOptions: DengageOptions.init(disableOpenURL: true/false
, badgeCountReset: true/false
, disableRegisterForRemoteNotifications: true/false)
, deviceId: “”, contactKey: “”, partnerDeviceId:””)
}

// make sure to keep import before Flipper related imports in AppDelegate.m
@import react_native_dengage; // ADD THIS IN IMPORTS

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  #ifdef FB_SONARKIT_ENABLED
    InitializeFlipper(application);
  #endif
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

  /**** Dengage Setup code Starting here ********/

  DengageRNCoordinator *coordinator = [DengageRNCoordinator staticInstance];
  [coordinator setupDengage:@"YOUR_INTEGERATION_KEY_HERE" launchOptions:launchOptions];

  /**** Dengage Setup code ends here ********/

  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"DengageExample"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

If you want diffrent configuration instead of default configuration you can add options parameter:
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

let dengageOptions = DengageOptions(disableOpenURL: <Bool>,
                                    badgeCountReset: <Bool>,
                                    disableRegisterForRemoteNotifications: <Bool>,
                                    enableGeofence: <Bool>)
        
Dengage.start(apiKey: "YOUR-DENGAGE-INTEGRATION-KEY", application: application, launchOptions: launchOptions, dengageOptions: DengageOptions())

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 New SDK method
import Dengage

UNUserNotificationCenter.current().delegate = self

Dengage.promptForPushNotifications()

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

// At the top import
import dEngage from '@dengage-tech/react-native-dengage'

// somewhere in your javascript/typescript code
dEngage.promptForPushNotifications()

//OR

// At the top import
import dEngage from '@dengage-tech/react-native-dengage'

// somewhere in your javascript/typescript code
dEngage.promptForPushNotificationsWitCallback((hasPermission: Boolean) => {
  // do somthing with hasPermission flag.
  // Note: hasPermission provides information if user enabled or disabled notification permission from iOS Settings > Notifications.
})

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.

// New SDK method
import Dengage

Dengage.set(contactKey: String)

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

// import statement
import dEngage from '@dengage-tech/react-native-dengage'

// in js/ts code
dEngage.setContactKey(userId: String)


// You may need getting current contact key from SDK. In that case you can use getContactKey
var contactkey = await dEngage.getContactKey()

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.

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

New SDK method: Push tokens can be set by Dengage.register(token: Data) 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.

// New SDK method
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Dengage.register(token: token)
}    
// At the top import
import dEngage from '@dengage-tech/react-native-dengage'

// setting the token that is taken manually
dEngage.setToken(token)

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

// At the top import New SDK method
import Dengage

let currentToken = Dengage.getToken()
// At the top import
import dEngage from '@dengage-tech/react-native-dengage'

// somewhere in your javascript/typescript code
const token = await 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

// New SDK method
let dengageOptions = DengageOptions(disableOpenURL: <Bool>,
                                    badgeCountReset: <Bool>,
                                    disableRegisterForRemoteNotifications: <Bool>,// default value: true
                                    enableGeofence: <Bool>)
        
Dengage.start(apiKey: "YOUR-DENGAGE-INTEGRATION-KEY", application: application, launchOptions: launchOptions, dengageOptions: DengageOptions())

User Permission Management (optional)

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

// New SDK method
import Dengage

Dengage.set(permission: Bool)

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

// At the top import
import dEngage from '@dengage-tech/react-native-dengage'

// somewhere in your javascript/typescript code
dEngage.setUserPermission(true)

// For getting last permission set by user
const permission = await dEngage.getUserPermission(true)

Logging

SDK can provide logs for debugging. It displays queries and payloads which are sent to REST APIs.

To validate your inputs you can enable SDK 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
}
// in imports
import {NativeEventEmitter, NativeModules} from 'react-native';

// in code
    React.useEffect(() => {
        // adding Listeners for new notification payload & it's on click handling.
        const eventEmitter = new NativeEventEmitter(NativeModules.DengageRN);
        const eventListener = eventEmitter.addListener('onNotificationClicked', (event) => {
            // handle notification here.
            console.log("onNotificationClicked")
            console.log(event)
        });

        return () => {
            eventListener?.remove?.();
        }
    }, [])

Google Tag Manager Implementation

You should use the protocol TAGCustomFunction.

TAGCustomFunction Protocol is automatically called by the tag manager internal SDK.

The execute function provides the dictionary which then can be feeded to our SDK for event collection

@objc func execute(withParameters parameters: [AnyHashable : Any]!) -> NSObject! {
        
        print(parameters ?? [:])

       ## you can use either of the two functions 
        Dengage.sendCustomEvent(eventTable: "test", parameters: [String:Any])
 
        Dengage.sendDeviceIdToServer(route: "test", token: "token")
        
        
    }
  

For GTM integration please refer

https://developers.google.com/tag-platform/tag-manager/ios/v5

https://developers.google.com/tag-platform/tag-manager/ios/v5/advanced-config

DeepLinking

SDK supports URL schema deep link. If the 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.

let options = DengageOptions(badgecountReset:true,
disableOpenURL:true, yy, true)
Dengage.start(with: "YOUR-DENGAGE-INTEGRATION-KEY",in:application, withLaunchOptions:launchOptions, options: options)

Troubleshooting
If you are sending push notifications from Dengage Dashboard, not getting any errors, but push notifications are not receiving to your devices, please follow steps described in Apple's Technical Note about Troubleshooting Push Notifications to verify if your device is successfully registering and receiving push notifications.


In App Inline

Dengage.showInAppInLine(propertyID : String? = nil , inAppInlineElement : InAppInlineElementView? = nil,screenName:String? = nil , customParams: Dictionary<String, String>? = nil , hideIfNotFound: Bool = false )

Here propertyID is the ios selector that you will be placing while creating campaign.

InApp inline element is the view that you will be placing where inapp inline is to be shown.

custom params is the dictionary for custom params filter that you will be placing on the panel while creating campaign.

screen name parameter is when the inapp inline is to be shown on the specific screen.

hide if not found is a parameter where user can tell the sdk whether hide the view if inappinline is not found.