Android Migration Steps
To migrate from manual code-based initialization to the XML file-based approach, follow these steps:
- Add configuration file :Add your generated
moengage.xml(or any .xml under res/values/ with the correct com_moengage_ resource entries) to the app module, in theandroid/app/src/main/res/values/moengage.xmlpath. - Update the Application class : In
android/app/src/main/java/<your/_package>/MainApplication.java(or.kt), remove theMoEngage.Buildersetup and call file-based initialization instead.
import com.moengage.capacitor.MoEInitializer;
@Override
public void onCreate() {
super.onCreate();
// ... existing code
MoEInitializer.initialiseDefaultInstance(this);
}import com.moengage.capacitor.MoEInitializer
override fun onCreate() {
super.onCreate()
// ... existing code
MoEInitializer.initialiseDefaultInstance(this)
}iOS Migration Steps
To migrate from code-based initialization to the Info.plist based approach, follow these steps:
- Update Info.plist: Add the required MoEngage configuration keys (for example, WorkspaceId, DataCenter, etc.) directly to 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.
import MoEngageSDK
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) - Bool {
// ... existing code
MoECapacitorInitializer.sharedInstance.intializeDefaultInstance()
return true
}#import <MoEngageSDK/MoEngageSDK.h>
import CapacitorMoengageCore
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ... existing code
[[MoECapacitorInitializer sharedInstance] intializeDefaultInstanceWithAdditionalConfig:[[MoEngageSDKDefaultInitializationConfig alloc] init]];
return true
}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.