MoEngage Docs

SDK Initialization

Initializing MoEngage SDK

First, go to Build Settings of your App Target and ensure that DEBUG Preprocessor Macro is defined in Debug section as shown in below image, if not present then add the same by entering DEBUG=1 in Debug section:

For Swift Project, In App Target Build Settings make sure -DDEBUG is added to Debug section in the Other Swift Flags as shown below:

Login to your MoEngage account, go to Settings in the left panel of the dashboard. Under General Settings, you will find your APP ID. Provide this APP ID while initializing the SDK with MOSDKConfig instance using initializeTestWithConfig: and initializeLiveWithConfig: methods as shown below.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            //TODO: Add your MoEngage App ID
        var yourMoEAppID = "Your App ID"
        var sdkConfig = MOSDKConfig.init(appID: yourMoEAppID)
            // Separate initialization methods for Dev and Prod initializations
        #if DEBUG
            MoEngage.sharedInstance().initializeTest(with: sdkConfig, andLaunchOptions: launchOptions)
            MoEngage.sharedInstance().initializeLive(with: sdkConfig, andLaunchOptions: launchOptions)
  //Rest of the implementation of method
  return true
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  //TODO: Add your MoEngage App ID
    NSString* yourMoEngageAppID = @"Your App ID";
    MOSDKConfig* sdkConfig = [[MOSDKConfig alloc] initWithAppID:yourMoEngageAppID];
    // MoEngage SDK Initialization
    // Separate initialization methods for Dev and Prod initializations
    #ifdef DEBUG
        [[MoEngage sharedInstance] initializeTestWithConfig:sdkConfig andLaunchOptions:launchOptions];
        [[MoEngage sharedInstance] initializeLiveWithConfig:sdkConfig andLaunchOptions:launchOptions];
  //Rest of the implementation of method



Make sure to call the initialization method in applicationDidFinishLaunching(_:) method.
In case if you are initializing the SDK at a later stage and not at launch then you will have to call all the notification related methods instead of just relying on AppDelegate Swizzling.

MOSDKConfig Properties

Starting from SDK version 7.0.0, we have introduced MOSDKConfig class to configure the SDK while initialization. Following properties can be configured using the instance of MOSDKConfig:

moeAppIDSet the MoEngage App ID to this property, you would find it in Dashboard Settings > General.
moeDataCenterSpecify the Data Center(Cluster) where your account is present. Possible values are DATA_CENTER_01 / DATA_CENTER_02 / DATA_CENTER_03. Refer doc for more info.
appGroupIDProvide the app Group ID configured for Push Notifications. Refer doc for more info.
analyticsDisablePeriodicFlushSDK by default syncs the data tracked periodically with the backend, in case you would want to disable the same set this property to true.
analyticsPeriodicFlushDurationIn 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.
encryptNetworkRequestsSet this property to true, in case you would want to encrypt all the network requests sent from the SDK.
optOutDataTrackingSet this property to true if you would want to opt-out of Data tracking from the SDK. Refer doc for more info.
optOutPushNotificationSet 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. Refer doc for more info.
optOutInAppCampaignSet this property to true if you would like to block the InApp campaigns in the app, by default this is set to false. Refer doc for more info.
optOutIDFATrackingSet the property to true if you want to opt-out of Advertising ID(IDFA) tracking, by default this is set to false. link
optOutIDFVTrackingSet the property to true if you want to opt-out of IDFV tracking, by default this is set to false. link

Update MOSDKConfig:

Post initializing the SDK if you would want to update any of the SDK config properties at a later point, use updateSDKConfig: method as shown below:

let currentConfig = MoEngage.sharedInstance().getDefaultSDKConfiguration()
currentConfig.analyticsDisablePeriodicFlush = true
MOSDKConfig* currentConfig = [[MoEngage sharedInstance] getDefaultSDKConfiguration];
currentConfig.analyticsDisablePeriodicFlush = true
[[MoEngage sharedInstance] updateSDKConfig:currentConfig];

Test/Live Environment

As mentioned above while initializing the build, MoEngage SDK makes use of the DEBUG preprocessor macro to decide whether the build is meant for TEST/LIVE Environment. Therefore you will have to take care of the same while generating the build and make sure that the Build Configuration of the App's target is set as mentioned below:

  • For Development Build: Build Configuration should be set to Debug (Data will be tracked in TEST Environment)
  • For AdHoc Build/App Store Build: Build Configuration should be set to Release (Data will be tracked in LIVE Environment)


What if Build Configuration is not set correctly?

If the build configuration is not set correctly following might happen:

  • You will see the data from the development build in LIVE environment
  • OR data from AdHoc/Production Build in TEST environment
  • You will get Bad Device Token error while trying to send a push notification to the device.

How to set Build Configuration?

Build Configuration on Running the app from Xcode:

Whenever you run the app directly from Xcode without archiving, make sure the build configuration of Run mode of the App Target in Edit Scheme is set to Debug(set by default settings). Doing this will make sure data is tracked in TEST Environment.

Build Configuration on Exporting the build:

While exporting the build make sure you set the correct Build Configuration. By default for Archive section in Edit Scheme the Build Configuration will be set to Release, but for a development build make sure its changed to Debug before exporting the build. To set the Build Configuration of the build in your Xcode project go to App Target > Edit Scheme > Archive > Build Configuration and set the configuration to Debug/Release(depending on the type of build). Refer to the image shown below:

Switching Environment in Dashboard:

In MoEngage dashboard you will observe, that we have provided test and live environment for your app. You can toggle between them using a switch as shown below :

TEST Environment is supposed to be used for all the development and testing related uses and LIVE environment is to be used for running all the campaigns for AppStore Builds for your app's user base.

Updated 2 months ago

What's Next

Now that you are done with AppDelegate changes, next we will see how to track App Installs and Updates

Install/Update differentiation

SDK Initialization

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.