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

# iOS SDK Initialization

> Initialize the MoEngage SDK in your Unity project's iOS configuration file with your workspace ID.

# Include MoEngage Configuration

After the MoEngage package is imported, include ***MoEngageConfiguration.h*** file in your Asset folder\
(`Asset > Import New Asset`). Download this configuration file from [here](https://github.com/moengage/MoEngage-Unity-SDK/blob/master/iOS/MoEngageConfiguration.h).

<Frame>
  <img src="https://mintcdn.com/moengage-partner-guide/XNC4qACqVHFkhQIR/images/iosSDKInitialization.png?fit=max&auto=format&n=XNC4qACqVHFkhQIR&q=85&s=48643d85a7ca010198639b25c307e9a5" alt="Ios SDK Initialization" width="2254" height="550" data-path="images/iosSDKInitialization.png" />
</Frame>

In your configuration file, set MoEngage App ID and Region along with other constants as shown below:

<CodeGroup>
  ```objectivec Objective-C theme={null}
  // MoEngage Account Identifier
  #define kMoEngageAppID @"YOUR WORKSPACE ID"

  /// Set DataCenter
  #define kMoEngageRegion NULL// DATA_CENTER_01/DATA_CENTER_02/DATA_CENTER_03/DATA_CENTER_04/DATA_CENTER_05

  /// Set Xcode console logs for debugging purpose
  #define kMoEngageLogsEnabled YES // YES/NO

  /// Enable UnityController Swizzling.
  #define kMoEngageUnityControllerSwizzlingEnabled YES // YES/NO

  /// Interval at which data must be send to MoEngage
  #define kMoEngageAnalyticsPeriodicFlushDuration 60 // Any value greater than 60

  ///  Bool to disable to periodic flush of events.
  #define kMoEngageAnalyticsDisablePeriodicFlush NO // YES/NO

  /// Inset value for nudge placement. Currently Nudge is not supported in Unity.
  #define kMoEngageInAppSafeArea 0

  /// Bool to enable Storage Encryption
  #define kMoEngageStorageEncryption NO  // YES/NO

  /// Set the keychain group name to save the encryption key in keychain
  #define KeyChainGroupName NULL

  /// If true sdk will encrypt all data in the API Request.
  #define kMoEngageNetworkEncryption NO // YES/NO

  /// Encryption Key of type String which will be use to encrypt/decrypt data in Debug mode.
  #define kMoEngageNetworkNetworkDebugKey NULL

  /// Encryption Key of type String which will be use to encrypt/decrypt data in Release mode
  #define kMoEngageNetworkNetworkReleaseKey NULL

  /// Jwt Configuration, if true all Network Request will be authenticated with jwt token
  #define kMoEngageDataSecurity NO // YES/NO
  ```
</CodeGroup>

# Unity App Controller Swizzling

There are two approaches using which the SDK can be initialized:

1. **Unity App Controller Subclass:**\
   SDK contains the `MoEUnityAppController` class which is the subclass of UnityAppController. Here we get a callback on AppLaunch to initialize MoEngage SDK.
2. **UnityAppController swizzling:**\
   Define `kMoEngageUnityControllerSwizzlingEnabled` in the configuration file and set it to `YES` to enable UnityAppController swizzling. Here `application:didfinishLaunchinWithOptions:` method is swizzled to initialize MoEngage SDK.

<Warning>
  UnityAppController swizzling (2nd approach) will be required if your project has multiple implementations of UnityAppController subclasses (1st approach), here the subclass defined in the plugin might not work reliably because here only one of the subclasses in the project will get the callbacks.
</Warning>

# Build and Replace

<Info>
  We make use of [CocoaPods](https://cocoapods.org/) for managing native dependencies, therefore make sure the same is installed in your system.
</Info>

Once required packages are imported go to `File > Build Settings`, switch to iOS platform, and click on `Build`. Select `Replace` in the pop-up. It's necessary to select **Replace** on first-time integration, this is because we will be updating the build settings of the Xcode project for MoEngage SDK and also installing the native dependencies via CocoaPods.

<Frame>
  <img src="https://mintcdn.com/moengage-partner-guide/qsdfsvW7sLL2Zxaa/images/IOSSDKIntialization2.png?fit=max&auto=format&n=qsdfsvW7sLL2Zxaa&q=85&s=ba7272f9bb20d2d99e444afbb7e9a2c2" alt="IOSSDK Intialization2" width="1168" height="792" data-path="images/IOSSDKIntialization2.png" />
</Frame>

After building the project in Unity Editor, open Unity-iPhone.xcworkspace in Xcode, and you are good to run the Unity-iPhone App.
