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 the 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 described in the image:
in to your MoEngage account, go to Settings in the left panel of the dashboard. Under General Settings, you will find your Workspace ID. Provide this Workspace ID while initializing the SDK with MOSDKConfig instance using initializeDefaultTestInstanceWithConfig: and initializeDefaultLiveInstanceWithConfig: methods as shown below.
import MoEngageSDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Add your MoEngage Workspace ID
var sdkConfig = MOSDKConfig(withAppID: "Your Workspace ID")
// Separate initialization methods for Dev and Prod initializations
#if DEBUG
MoEngage.sharedInstance().initializeDefaultTestInstance(with: sdkConfig, andLaunchOptions: launchOptions)
#else
MoEngage.sharedInstance().initializeDefaultLiveInstance(with: sdkConfig, andLaunchOptions: launchOptions)
#endif
//Rest of the implementation of method
//-------
return true
}
@import MoEngageSDK;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//TODO: Add your MoEngage Workspace ID
MOSDKConfig* sdkConfig = [[MOSDKConfig alloc] initWithAppID:@"YOUR Workspace ID"];
// MoEngage SDK Initialization
// Separate initialization methods for Dev and Prod initializations
#ifdef DEBUG
[[MoEngage sharedInstance] initializeDefaultTestInstanceWithConfig:sdkConfig andLaunchOptions:nil];
#else
[[MoEngage sharedInstance] initializeDefaultLiveInstanceWithConfig:sdkConfig andLaunchOptions:nil];
#endif
//Rest of the implementation of method
//-------
}
warning |
Important Make sure to call the initialization method in |
MOSDKConfig Properties
Following properties can be configured using the instance of MOSDKConfig for SDK version 8.2.0
Property | Description |
---|---|
moeDataCenter | Specify the Data Center(Cluster) where your account is present. Possible values are data_center_01/data_center_02/data_center_03.Refer to doc for more info. |
appGroupID | Provide the app Group ID configured for Push Notifications. Refer to doc for more info. |
analyticsDisablePeriodicFlush | SDK by default syncs the data tracked periodically with the backend, in case you would want to disable the same set this property to true. |
analyticsPeriodicFlushDuration | In 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. |
encryptNetworkRequests | Set this property to true, in case you would want to encrypt all the network requests sent from the SDK. |
enableLogs |
Set this property to true if you would want to see the all the logs related to MoEngage SDK. |
inAppConfig |
Set this property to add safe area inset in IOS in-app nudges. For example: sdkConfig.inAppConfig = MoEngageInAppConfig(safeAreaInset: 200) |
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)
warning |
What if Build Configuration is not set correctly? If the build configuration is not set correctly following might happen:
|
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 as described:
Switching Environment in Dashboard
In the MoEngage dashboard you can switch between test and live environment for your app.
TEST Environment is used for all the development and testing-related uses and LIVE environment is used for running all the campaigns for AppStore Builds for your app's user base.