iOS Integration

SDK Installation

Installation via. CocoaPods(Plugin Version 5.0.0 and above)

Starting from cordova-ios version 4.3.0 and cordova-cli version 6.4.0, CocoaPod support is provided to bundle any iOS framework. Therefore, we have updated our plugin too to support this from version 5.0.0.

Cocoapods is a dependency manager for iOS projects and makes integration easier. If you don't have cocoapods installed, you can do it by executing the following command in your terminal:

sudo gem install cocoapods

Here, after adding the plugin just go to the ios folder in platforms and run pod install command to integrate our MoEPluginBase:

pod repo update
pod install

Bundled Integration(Only for Plugin Version 4.2.0 and below)

MoEngage Framework in Embedded Binaries

Ensure that the MoEngage.framework is present in Embedded Binaries(General > Embedded Binaries ). If not present then add the same.


Add script to remove Unwanted Architectures

Do this if not already done: Select App Target and go to Build Phase and add a Run Script step to your build steps, set it to use /bin/sh and enter the following script:

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
    echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

    EXTRACTED_ARCHS=()

    for ARCH in $ARCHS
    do
        echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
        lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
        EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
    done

    echo "Merging extracted architectures: ${ARCHS}"
    lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
    rm "${EXTRACTED_ARCHS[@]}"

    echo "Replacing original executable with thinned version"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

This script is for removing unsupported architectures while exporting the build OR submitting app to the app store.

🚧

For Plugin version 3.2.0 and below:

Open your project in Xcode, select your project. Go to Build Settings -> Linker -> Other Linker Flags and add -ObjC flag.


SDK Initialization

Default Initialization

By default the project gets initiailzed with Configuration from Info.plist as shown below:

🚧

SDK Configuration from Info.plist

Prior to SDK version 7.1.1, only MoEngage_APP_ID could be configured from your plist file. Now from version 7.1.1 and above, there are additional properties that can be configured along with the AppID as shown in the above image.

Following are the additional properties of SDK that can be configured in Info.plist [From Plugin Version 7.1.1]:

Property

Description

APP_GROUP_ID

Provide the app Group ID configured for Push Notifications and to share data between App and Extensions

DATA_CENTER

Specify the Data Center(Cluster) where your account is present. Possible values are DATA_CENTER_01 / DATA_CENTER_02 / DATA_CENTER_03.

DISABLE_PERIODIC_FLUSH

SDK by default syncs the data tracked periodically with the backend, in case you would want to disable the same set this property to true.

PERIODIC_FLUSH_DURATION

In case you want to define the interval for periodic sync, set the value in seconds here. Please note that the value should be greater than 60 secs.

ENCRYPT_NETWORK_REQUESTS

Set this property to true, in case you would want to encrypt all the network requests sent from the SDK.

OPT_OUT_DATA_TRACKING

Set this property to true if you would want to opt-out of Data tracking from the SDK.

OPT_OUT_PUSH_NOTIFICATIONS

Set this property to true if you would like to stop push campaigns to be sent to the app, by default this is set to false.

OPT_OUT_INAPP

Set this property to true if you would like to block the InApp campaigns in the app, by default this is set to false.

OPT_OUT_IDFA_TRACKING

Set the property to true if you want to opt-out of Advertising ID(IDFA) tracking, by default this is set to false

OPT_OUT_IDFV_TRACKING

Set the property to true if you want to opt-out of IDFV tracking, by default this is set to false.


Code Initialisation

From plugin version 7.1.1 and above, we support code initialization as well. For this first, disable the default SDK initialization from Info.plist by doing the following:

  • Go to info.plist of your project.
  • Inside MoEngage dictionary, Add DISABLE_PLIST_INITIALIZATION key and set to true.

❗️

IMPORTANT:

DISABLE_PLIST_INITIALIZATION key must be present in Info.plist to support Code Initialization as shown in the image below.


  • Post disabling default Initialization, call any one of the below-given initialization methods in application:didFinishLaunchingWithOptions: method. The method accepts the MOSDKConfig instance as its parameter. Refer doc for more info on all the properties which can be configured using MOSDKConfig.
/// @param sdkConfig MOSDKConfig instance for SDK configuration
/// @param launchOptions Launch Options dictionary
- (void)initializeMoEngageSDKWithConfig:(MOSDKConfig*)sdkConfig andLaunchOptions:(NSDictionary*)launchOptions;

/// @param sdkConfig MOSDKConfig instance for SDK configuration
/// @param isSdkEnabled Bool indicating if SDK is Enabled/Disabled, refer: https://docs.moengage.com/docs/gdpr-compliance-1#enabledisable-sdk
/// @param launchOptions Launch Options dictionary
- (void)initializeMoEngageSDKWithConfig:(MOSDKConfig*)sdkConfig withSDKState:(BOOL)isSdkEnabled andLaunchOptions:(NSDictionary*)launchOptions;
  • Sample code to initialise from application:didFinishLaunchingWithOptions: method:
#import "AppDelegate.h"
#import "MainViewController.h"
  
// Make sure to import "AppDelegate+MoEngage.h"
#import "AppDelegate+MoEngage.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.viewController = [[MainViewController alloc] init];
    
    MOSDKConfig *sdkConfig = [[MOSDKConfig new] initWithAppID: @"Your MoEngage App ID"];
    sdkConfig.moeDataCenter = DATA_CENTER_01 // Possible Values DATA_CENTER_01/DATA_CENTER_02/ DATA_CENTER_03
    sdkConfig.appGroupID = "App Group ID"

    // ---
    // Update other Parameters of SDK Config
    // ---
    [self initializeMoEngageSDKWithConfig:sdkConfig andLaunchOptions:launchOptions];
    
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end