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.
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 #define kMoEngageRegion NULL// DATA_CENTER_01/DATA_CENTER_02/DATA_CENTER_03/DATA_CENTER_04/DATA_CENTER_05 /// 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:
Unity App Controller Subclass:
SDK contains the
MoEUnityAppControllerclass which is the subclass of UnityAppController. Here we get a callback on AppLaunch to initialize MoEngage SDK.
kMoEngageUnityControllerSwizzlingEnabledin the configuration file and set it to
YESto 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
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.
After building the project in Unity Editor, open Unity-iPhone.xcworkspace in Xcode and you are good to run the Unity-iPhone App.