MoEngage Docs

AppDelegate Changes

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 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 shown below:

Login to your MoEngage account, go to Settings in the left panel of the dashboard. Under App Settings, you will find your APP ID. Provide this APP ID while initializing the SDK with initializeDevWithApiKey: and initializeProdWithApiKey: methods as shown below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  	// Separate initialization methods for Dev and Prod initializations 
  	// openDeeplinkUrlAutomatically tells us whether you want the SDK to call handleOpenUrl for deeplinks specified while creating a campaign
    #ifdef DEBUG
    	[[MoEngage sharedInstance] initializeDevWithApiKey:@"Your APP ID" inApplication:application withLaunchOptions:launchOption openDeeplinkUrlAutomatically:YES];
    #else
    	[[MoEngage sharedInstance] initializeProdWithApiKey:@"Your APP ID" inApplication:application withLaunchOptions:launchOption openDeeplinkUrlAutomatically:YES];
    #endif
  	//Rest of the implementation of method
		//-------
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
	// Separate initialization methods for Dev and Prod initializations
	// openDeeplinkUrlAutomatically tells us whether you want the SDK to call handleOpenUrl for deeplinks specified while creating a campaign
	#if DEBUG
            MoEngage.sharedInstance().initializeDev(withApiKey: "Your APP ID", in: application, withLaunchOptions: launchOptions, openDeeplinkUrlAutomatically: true)
	#else
            MoEngage.sharedInstance().initializeProd(withApiKey: "Your APP ID", in: application, withLaunchOptions: launchOptions, openDeeplinkUrlAutomatically: true)
	#endif
	//Rest of the implementation of method
	//-------
	return true
}

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)

What if Build Configuration is not set correctly?

If the build configuration is not set correctly following might happen:

  • You will see the data from the development build in LIVE environment
  • OR data from AdHoc/Production Build in TEST environment
  • You will get Bad Device Token error while trying to send a push notification to the device.

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 shown below :

Switching Environment in Dashboard:

In MoEngage dashboard you will observe, that we have provided test and live environment for your app. You can toggle between them using a switch as shown below :

TEST Environment is supposed to be used for all the development and testing related uses and LIVE environment is to be used for running all the campaigns for AppStore Builds for your app's user base.


What's Next

Now that you are done with AppDelegate changes, next we will see how to track App Installs and Updates

Install/Update differentiation