MoEngage Docs

SDK Integration

How to integrate iOS SDK into your app

There are two ways you can integrate the SDK - CocoaPods or Manual integration. We recommend CocoaPods.

IMPORTANT :

  • The current SDK supports iOS8 and above

  • Refer to sample project for queries regarding integration of MoEngage iOS SDK

Integration through CocoaPods

Cocoapods is a dependency manager for Objective C & Swift projects and makes integration easier.

  1. If you don't have cocoapods installed, you can do it by executing the following line in your terminal.
sudo gem install cocoapods
  1. If you don't have a Podfile, create a plain text file named Podfile in the Xcode project directory with the following content, making sure to set the platform and version that matches your app.
pod 'MoEngage-iOS-SDK'
  1. Install MoEngage SDK by executing the following in the Xcode project directory.
pod install
  1. Now, open your project workspace and check if MoEngage SDK is properly added.

Manual Integration

To install manually, follow the steps below:

  1. Download the latest sdk from the following link.

  2. Add the MoEngage.framework file to your project.

  3. Add MoEngage framework to Embedded Binaries

  4. Do this if not already done: Select App Target and go to Build Phase and add a Run Script step to your build steps, set it to use /bin/sh and enter the following script:

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
    echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

    EXTRACTED_ARCHS=()

    for ARCH in $ARCHS
    do
        echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
        lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
        EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
    done

    echo "Merging extracted architectures: ${ARCHS}"
    lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
    rm "${EXTRACTED_ARCHS[@]}"

    echo "Replacing original executable with thinned version"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

This script is for removing unsupported architectures while exporting the build OR submitting app to app store.

Migration from SDK Version 3.* to 4.*

MoEngage SDK was distributed as static library till 3.9.2 and with the release of MoEngage iOS SDK 4.0.0, we have implemented the SDK as a dynamic framework. And also with version 4.0.0 and above, there are few changes which you will have to do in your project if you are migrating from SDK version 3.9.2 and below.

Changes in the import statements

For SDK Version 3.9.2 and below the MoEngage SDK was being imported as shown below :

// For SDK version 3.9.2 and below
#import "MoEngage.h"

// OR in ObjC bridging header
#import <MoEngage_iOS_SDK/MoEngage.h>
// For SDK version 3.9.2 and below
import MoEngage_iOS_SDK

And now for SDK version 4.0.0 and above there are minor changes to import statement. Now import MoEngage as shown below :

#import <MoEngage/MoEngage.h>
import MoEngage

Deprecated Methods

The following methods have been deprecated with SDK version 4.0.0:

  • registerForRemoteNotificationWithCategories:andCategoriesForPreviousVersions:andWithUserNotificationCenterDelegate: method has been deprecated and now we have 2 separate methods for registering for remote notification. For more info refer this link

  • registerForPush: is deprecated and replaced with setPushToken: as the method name was confused with the one provided for registering for push notification. Refer link for more info.

Removed Deprecated methods

With SDK Version 4.0.0, we have removed the following application lifecycle callback methods, which were already deprecated in SDK version 3.3.0:

-(void)applicationBecameActiveinApplication:(UIApplication*)application;
-(void)applicationWillEnterForeground:(UIApplication *)application;
-(void)stop:(UIApplication *)application;
-(void)applicationTerminated:(UIApplication*)application;

If you get an error because of the above methods, remove the function calls as SDK is internally handling the application lifecycle callbacks.

Inbox Module source files are no longer exposed

With the release of 4.0.0, the inbox module source files(MOInboxTableViewCell.m, MOInboxViewController.m and MOInboxExposedConstants.m) will no longer be exposed. For customizing the Notification Center UI use the methods provided in MOInbox class.


What's Next

Awesome, you are all set to use MoEngage now. Next we will see how to initialize MoEngage SDK and changes that are to be made to your AppDelegate file.

AppDelegate Changes