> ## Documentation Index
> Fetch the complete documentation index at: https://moengage.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS Kit Integration

Integrate the mParticle iOS SDK before starting with MoEngage Kit Integration. Refer to the [developer documentation](https://docs.mparticle.com/developers/sdk/ios/initialization) and [Kit integration documentation](https://docs.mparticle.com/developers/client-sdks/ios/kits/) for more information. Skip this step if mParticle iOS SDK is already integrated into the application.

# MoEngage Kit Integration

## SDK Installation

### Installing using SPM

1. Navigate to Project's settings -> Package Dependencies -> Add Package
2. Enter the URL [https://github.com/moengage/mparticle-apple-integration-moengage.git](https://github.com/moengage/mparticle-apple-integration-moengage.git) and select the branch as master or required version to install the package.
3. Click on **Add Package**.
4. Select **mParticle-MoEngage** product for your app target.

### Installing using CocoaPods

Add the kit dependency to your app's **Podfile** as shown below:

<CodeGroup>
  ```ruby Ruby theme={null}
  pod 'mParticle-MoEngage','~> 1.0.0'
  ```
</CodeGroup>

## Configure MoEngage SDK

1. Disable MoEngageSDK method swizzling by setting **MoEngageAppDelegateProxyEnabled** as **false** /**NO** in app's **Info.plist**.
2. Get Workspace ID (earlier App ID) from the Settings Page Dashboard --> Settings --> Account --> General and configure the MoEngage SDK in the ***AppDelegate's didFinishLaunchingWithOptions*** callback \_\_ before initializing the mParticle Kit.

<CodeGroup>
  ```swift Swift wrap theme={null}
  import MoEngageSDK
  import mParticle_Apple_SDK
  import mParticle_MoEngage
   
   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      // Add your MoEngage Workspace ID and Data center.
      let sdkConfig = MoEngageSDKConfig(appId: "YOUR WorkspaceID", dataCenter: DATA_CENTER)
      // MoEngage SDK configuration
      MoEngageConfigurator.configureDefaultInstance(sdkConfig: sdkConfig)
   
      // Initialize mParticle
      let mParticleOptions = MParticleOptions(key: "YOU MPARTICLE API KEY", secret: "YOUR MPARTICLE API SECRET")
      MParticle.sharedInstance().start(with: mParticleOptions)
   
      // Rest of the implementation of method
      //-------
      return true
  }
  ```

  ```objectivec Objective-C theme={null}
  @import MoEngageSDK;
  @import mParticle_Apple_SDK;
  @import mParticle_MoEngage;
   
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       // Add your MoEngage Workspace ID and Data center.
       MoEngageSDKConfig* sdkConfig = [[MoEngageSDKConfig alloc] initWithAppId:@"YOUR Workspace ID" dataCenter: DATA_CENTER];
      // MoEngage SDK configuration
      [MoEngageConfigurator configureDefaultInstanceWithSdkConfig:sdkConfig];
   
      // Initialize mParticle
      MParticleOptions* mParticleOptions = [MParticleOptions optionsWithKey:@"YOU MPARTICLE API KEY" secret:@"YOUR MPARTICLE API SECRET"];
      [[MParticle sharedInstance] startWithOptions:mParticleOptions];
      
      //Rest of the implementation of method
      //-------
  }
  ```
</CodeGroup>

# Install / Update Differentiation :

Since you might integrate us when your app is already on the App Store, we would need to know whether your app update would be an actual **UPDATE** or an **INSTALL**. To differentiate between those, use one of the methods below:

<CodeGroup>
  ```swift Swift theme={null}
  //For Fresh Install of App
  MoEngageSDKAnalytics.sharedInstance.appStatus(.install)
  // For Existing user who has updated the app
  MoEngageSDKAnalytics.sharedInstance.appStatus(.update)
  ```

  ```objectivec Objective-C theme={null}
  //For Fresh Install of App
  [[MoEngageSDKAnalytics sharedInstance]appStatus:MoEngageAppStatusInstall];
  // For Existing user who has updated the app
  [[MoEngageSDKAnalytics sharedInstance]appStatus:MoEngageAppStatusUpdate];
  ```
</CodeGroup>

For more info on this refer to the following [link](https://www.moengage.com/docs/developer-guide/ios-sdk/data-tracking/basic/install-update-differentiation).

# Handling Push Notifications

### Configuring with mParticle SDK

mParticle SDK provides a way to handle the registration of push token and receive push notifications at the mParticle SDK. Refer [Push integration doc](https://www.moengage.com/docs/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial) for the configuration option.

### Configuring with MoEngage SDK or with Application

Check the[ MoEngage Push integration doc](https://www.moengage.com/docs/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial)) to configure with MoEngage SDK or if you want to handle it independently.

For more information on features provided in MoEngage iOS SDK refer to the following links:

* [Push Notifications](https://www.moengage.com/docs/developer-guide/android-sdk/push/basic/push-configuration)
* [Geofence](https://www.moengage.com/docs/developer-guide/android-sdk/push/optional/location-triggered)
* [In-App messaging](https://www.moengage.com/docs/developer-guide/android-sdk/in-app-messages/in-app-nativ)
* [Notification Center](https://developers.moengage.com/hc/en-us/articles/4403893700756-Notification-Center-for-MoEngage-SDK-version-11-1-00-)
* [Advanced Configuration](https://www.moengage.com/docs/developer-guide/android-sdk/push/advanced/callbacks-and-customisation)
* [API Reference](https://moengage.github.io/android-api-reference/index.html)
* [Compliance](https://www.moengage.com/docs/developer-guide/android-sdk/compliance/prepare-for-google-plays-data-disclosure-requirements)
* [Release Notes](/release-notes/sdks/android#14th-december-2023)

# mParticle SDK Usage

Refer to the [developer documentation](https://docs.mparticle.com/developers/client-sdks/ios/initialization/) for detailed usage.

## User Management

User identity is managed through a combination of mParticle's IDSync framework and MoEngage's user profiles.

Check [IDSync](https://docs.mparticle.com/developers/client-sdks/ios/idsync/) documentation from the mParticle developer integration document to manage the user state in the application.

By default, our integration automatically maps the following core mParticle identifiers to MoEngage user attributes without any extra code:

* customerId
* email
* mobileNumber

### Mapping Additional Identifiers

To synchronise other identifiers (e.g., social media IDs, internal aliases), you must explicitly map them using the ***setMappingForIdentity(),*** method. This ensures that when an identifier is added or updated through an mParticle ***setIdentity*** API call, the change is reflected in the corresponding MoEngage user attribute.

#### When to Call

This setup must be performed at a specific point in your app's startup sequence:

1. **After** you initialize the MoEngage SDK.
2. **Before** you call mParticle's ***setIdentity*** API for the first time.

The best place for this logic is in your **UIApplicationDelegate's didFinishLaunchingWithOptions** callback.

<CodeGroup>
  ```swift Swift theme={null}
  // In your UIApplicationDelegate's didFinishLaunchingWithOptions callback
  // 1. Define the mappings
  let identities: [MPIdentity: String] = [:]
  //
  // 2. Set the Identity mapping for mParticle and MoEngage
  // Example Usage: setMapping(forIdentities: [.facebook: "u_fb"])
  //
  MoEngageConfigurator.setMapping(forIdentities: identities)
  ```

  ```objectivec Objective-C theme={null}
  // In your UIApplicationDelegate's didFinishLaunchingWithOptions callback
  // 1. Define the mappings
  NSDictionary<mpidentity, nsstring="NSString"> *identities = @{};
   
  //
  // 2. Set the Identity mapping for mParticle and MoEngage
  // Example Usage: setMappingForIdentities:@{MPIdentityFacebook: @"u_fb"})
  //
  [MoEngageConfigurator setMappingForIdentities:identities];</mpidentity,>
  ```
</CodeGroup>

## Event Tracking

Use [logEvent](https://docs.mparticle.com/developers/client-sdks/ios/event-tracking/) to track the custom and commerce events from mParticle SDK. mParticle SDK will send the event to MoEngage Kit (if configured from mParticle Dashboard) with associated profiles.

## User Attribute Tracking

mParticle SDK provides [setUserAttributeList](https://docs.mparticle.com/developers/client-sdks/ios/users/) to set the user attributes. Either you can set the mParticle standard attributes or custom attributes both are passed to MoEngage Kit and mapped accordingly at MoEngage SDK.

# Sample Implementation

Refer to [this](https://github.com/moengage/mparticle-apple-integration-moengage) GitHub repository for a sample implementation.
