iOS SDK Initialization

Include MoEngage Configuration

After the MoEngage package is imported, include MoEngageConfiguration.h file in your Asset folder
(Asset > Import New Asset). Download this configuration file from here.

Screenshot 2023-08-11 at 11.18.57 AM.png

In your configuration file, set MoEngage App ID and Region along with other constants as shown below:

// MoEngage Account Identifier
#define kMoEngageAppID @"YOUR APPID"

/// Set DataCenter

/// Set Xcode console logs for debugging purpose
#define kMoEngageLogsEnabled YES // YES/NO

/// Enable UnityController Swizzling.
#define kMoEngageUnityControllerSwizzlingEnabled YES // YES/NO

/// Interval at which data must be send to MoEngage
#define kMoEngageAnalyticsPeriodicFlushDuration 60 // Any value greater than 60

///  Bool to disable to periodic flush of events.
#define kMoEngageAnalyticsDisablePeriodicFlush NO // YES/NO

/// Inset value for nudge placement. Currently Nudge is not supported in Unity.
#define kMoEngageInAppSafeArea 0

/// Bool to enable Storage Encryption
#define kMoEngageStorageEncryption NO  // YES/NO

/// Set the keychain group name to save the encryption key in keychain
#define KeyChainGroupName NULL

/// If true sdk will encrypt all data in the API Request.
#define kMoEngageNetworkEncryption NO // YES/NO

/// Encryption Key of type String which will be use to encrypt/decrypt data in Debug mode.
#define kMoEngageNetworkNetworkDebugKey NULL

/// Encryption Key of type String which will be use to encrypt/decrypt data in Release mode
#define kMoEngageNetworkNetworkReleaseKey NULL

/// Jwt Configuration, if true all Network Request will be authenticated with jwt token
#define kMoEngageDataSecurity NO // YES/NO

Unity App Controller Swizzling

There are two approaches using which the SDK can be initialized:

  1. Unity App Controller Subclass:
    SDK contains the MoEUnityAppController class which is the subclass of UnityAppController. Here we get a callback on AppLaunch to initialize MoEngage SDK.

  2. UnityAppController swizzling:
    Define kMoEngageUnityControllerSwizzlingEnabled in the configuration file and set it to YES to enable UnityAppController swizzling. Here application:didfinishLaunchinWithOptions: method is swizzled to initialize MoEngage SDK.



UnityAppController swizzling(2nd approach) will be required if your project has multiple implementations of UnityAppController subclasses(1st approach), here the subclass defined in the plugin might not work reliably because here only one of the subclasses in the project will get the callbacks.

Build and Replace



We make use of CocoaPods for managing native dependencies, therefore make sure the same is installed in your system.

Once required packages are imported go to File > Build Settings, switch to iOS platform, and click on Build. Select Replace in the pop-up. It's necessary to select Replace on first-time integration, this is because we will be updating the build settings of the Xcode project for MoEngage SDK and also installing the native dependencies via CocoaPods.

Screenshot 2023-08-11 at 2.40.50 PM.png

After building the project in Unity Editor, open Unity-iPhone.xcworkspace in Xcode and you are good to run the Unity-iPhone App.

Was this article helpful?
0 out of 1 found this helpful

How can we improve this article?