Android Migration Steps
To migrate from manual code-based initialization to the XML file-based approach, follow the below steps:- Add Configuration File: Place the
moengage_configfile in the (src/main/assets/moengage.xml) path. - Update Application Class: Remove the existing initialization code (the manual
MoEngage.Builderlogic) from your Application class and replace it with the default instance initialization to enable reading from the XML file.
| Code Language | Existing Code | Replace with |
|---|---|---|
| Kotlin | val moEngage: MoEngage.Builder = MoEngage.Builder(this,“YOUR_Workspace_ID”, DataCenter.DATA_CENTER_X) | MoEInitializer.initializeDefaultInstance(application) |
| Java | MoEngage.Builder moEngage = new MoEngage.Builder(this, “YOUR_Workspace_ID”, YOUR_DATA_CENTER); MoEInitializer.initialiseDefaultInstance(this, moEngage); | MoEInitializer.INSTANCE.initializeDefaultInstance(this); |
iOS Migration Steps
To migrate from code-based initialization to theInfo.plist based approach, follow these steps:
- Update Info.plist: Add the required MoEngage configuration keys (e.g., WorkspaceId, DataCenter) inside the MoEngage key in your
Info.plistfile. - Update AppDelegate: Remove the existing initialization code (the manual MoEngageSDKConfig logic) from your
AppDelegateclass and replace it with the default instance initialization to enable reading from theInfo.plistfile.
| Code Language | Existing Code | Replace with |
|---|---|---|
| Swift | MoEngageInitializer.sharedInstance.initializeDefaultInstance(sdkConfig, launchOptions: launchOptions) | MoEngageInitializer.sharedInstance.initializeDefaultInstance() |
| Objective-C | [[MoEngageInitializer sharedInstance] initializeDefaultInstance:sdkConfig launchOptions:launchOptions]; | [MoEngageInitializer.sharedInstance initializeDefaultInstance]; |
Precedence Rules
The source of configuration is determined by the initialization function called in your native code:- Android:
- File-Based Init: Calling
MoEInitializer.initializeDefaultInstance(context)instructs the SDK to look for and read themoengage.xmlfile. - Code-Based Init: Calling
MoEInitializer.initialize(context, moEngage.Builder)will initialize the SDK using the configuration object passed in the parameters, ignoring the XML file even if it exists.
- File-Based Init: Calling
- iOS: Auto-initialization (via
Info.plist) occurs first. However, if you subsequently call the manualinitializemethod with a configuration object in your code, it will update the current instance configuration.