For initializing the project, you'll need to provide the Workspace ID of your MoEngage Workspace.
info |
Note Login to your MoEngage account, go to Settings in the left panel of the dashboard. Under App Settings, you will find your Workspace ID. |
- Go to Info.plist of your project.
- Create MoEngage dictionary
- Inside MoEngage dictionary, Add MoEngage_APP_ID key and provide Workspace ID.
Following are the additional properties of SDK that can be configured in Info.plist
[From Plugin Version 7.1.1
]:
Property | Description |
---|---|
APP_GROUP_ID | Provide the app Group ID configured for Push Notifications and to share data between App and Extensions |
DATA_CENTER | Specify the Data Center(Cluster) where your account is present. Possible values are DATA_CENTER_01 / DATA_CENTER_02 / DATA_CENTER_03/ DATA_CENTER_04. |
DISABLE_PERIODIC_FLUSH | 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. |
PERIODIC_FLUSH_DURATION | 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. |
ENCRYPT_NETWORK_REQUESTS | Set this property to true, in case you would want to encrypt all the network requests sent from the SDK. |
ENABLE_LOGS | Set this property to true, to see the console logs |
warning |
Warning Make sure to call the below |
Once the AppID changes are done, go to your AppDelegate
file and call any one of the below initialization method in application:didFinishLaunchingWithOptions:
method:
/// @param sdkConfig MoEngageSDKConfig instance for SDK configuration
/// @param launchOptions Launch Options dictionary
- (void)initializeDefaultInstance:(NSDictionary*)launchOptions;
/// @param sdkConfig MoEngageSDKConfig instance for SDK configuration
/// @param isSdkEnabled Bool indicating if SDK is Enabled/Disabled
/// @param launchOptions Launch Options dictionary
- (void)initializeDefaultInstance:(BOOL)isSdkEnabled andLaunchOptions:(NSDictionary*)launchOptions;
Sample code to initialise from application:didFinishLaunchingWithOptions:
method:
Note: For swift applications add #import <ReactNativeMoEngage/MoEngageInitializer.h> in App-Bridging-Header.h file
import MoEngageSDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
MoEngageInitializer.sharedInstance().initializeDefaultInstance(launchOptions)
//Rest of the implementation of method
//-------
return true
}
#import <ReactNativeMoEngage/MoEngageInitializer.h>
#import <MoEngageSDK/MoEngageSDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
[[MoEngageInitializer sharedInstance] initializeDefaultInstance:launchOptions];
return YES;
}
Code Initialisation
To initialize MoEngageSDK from application:didFinishLaunchingWithOptions:
without adding any keys to Info.plist, call any one of the below initialization method by passing MoEngageSDKConfig
as parameter.Refer doc for more info on all the properties which can be configured using MoEngageSDKConfig
.
Objective-C
/// @param sdkConfig MoEngageSDKConfig instance for SDK configuration
/// @param launchOptions Launch Options dictionary
- (void)initializeDefaultSDKConfig:(MoEngageSDKConfig*)sdkConfig andLaunchOptions:(NSDictionary*)launchOptions;
/// @param sdkConfig MoEngageSDKConfig instance for SDK configuration
/// @param isSdkEnabled Bool indicating if SDK is Enabled/Disabled
/// @param launchOptions Launch Options dictionary
- (void)initializeDefaultSDKConfig:(MoEngageSDKConfig*)sdkConfig withSDKState:(BOOL)isSdkEnabled andLaunchOptions:(NSDictionary*)launchOptions;
Sample code to initialise from application:didFinishLaunchingWithOptions:
method:
import MoEngageSDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Add your MoEngage App ID and Data center.
let sdkConfig = MoEngageSDKConfig(withAppID: "YOUR Workspace ID")
sdkConfig.enableLogs = true
MoEngageInitializer.sharedInstance().initializeDefaultSDKConfig(sdkConfig, andLaunchOptions: launchOptions)
//Rest of the implementation of method
//-------
return true
}
#import <ReactNativeMoEngage/MoEngageInitializer.h>
#import <MoEngageSDK/MoEngageSDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
MoEngageSDKConfig* sdkConfig = [[MoEngageSDKConfig alloc] initWithAppID:@"YOUR Workspace ID"];
sdkConfig.enableLogs = true;
[[MoEngageInitializer sharedInstance] initializeDefaultSDKConfig:sdkConfig andLaunchOptions:launchOptions];
return YES;
}