# 2. Install the Airflux SDK

## 1. SDK Installation

The Airflux SDK can be installed using various dependency management tools. Choose one of the following methods to add the SDK to your project.

{% tabs %}
{% tab title="Swift Package Manager" %}

1. In the Xcode menu bar, click \[File] > \[Add Packages...]
2. In the top-right search bar, enter the following URL and then click \[Add Package].

   <https://github.com/ab180/airflux-ios-sdk-deployment>
3. Confirm the detected package and continue to click \[Add Package] to complete the installation.
4. You can confirm that the Airbridge SDK has been added under Package Dependencies in the Project Navigator.&#x20;
   {% endtab %}

{% tab title="CocoaPods" %}

#### 1.1 User Script Sandboxing

In Xcode's `Build Settings`, set `User Script Sandboxing` to `No`. For more details, refer to the [CocoaPods](https://github.com/CocoaPods/CocoaPods/issues/11946) documentation.

#### 1.2 Install CocoaPods and Set Up the Podfile

1. In your macOS Terminal, install CocoaPods using the following command: `brew install cocoapods`
2. Navigate to your Xcode project folder. The easiest way is to type `cd` and then drag your project folder directly into the Terminal window: `cd /path/to/your/XcodeProject`
3. Run this command to create a `Podfile`: `pod init`
4. Open the `Podfile` and add the following code to the `target` block.&#x20;

   Replace `$HERE_LATEST_VERSION` with the latest SDK version, available on the [Airflux SDK Versions page](https://docs.airflux.ai/sdk-release-note/ios-sdk-release-note).

{% code title="Podfile" %}

```kotlin
target '[Project Name]' do
    ...
    # Replace $HERE_LATEST_VERSION with latest version
    # - Example: pod 'airflux-ios-sdk', '4.X.X'
    pod 'airflux-ios-sdk', '$HERE_LATEST_VERSION'
    ...
end
```

{% endcode %}

#### 1.3 Open Your Xcode Project

After installation, you must open the `YOUR_PROJECT.xcworkspace` file from now on. This file contains both your app project and the installed Pods. **Do not open the old `.xcodeproj` file**
{% endtab %}

{% tab title="Tuist" %}
{% hint style="info" %}
The Airflux iOS SDK cannot be installed using Tuist's [XcodeProj-based integration](https://docs.tuist.dev/en/guides/features/projects/dependencies#tuists-xcodeprojbased-integration). You must use Xcode's [default integration method](https://docs.tuist.dev/en/guides/features/projects/dependencies#xcodes-default-integration) for installation.
{% endhint %}

1. Run the `tuist edit` command in your Terminal.
2. Add the SDK as a remote package in the `project.packages` block. Then, add the SDK as a `package` dependency to `project.targets[...].target.dependencies`.

   * Replace `$HERE_LATEST_VERSION` with the latest SDK version, available on the [Airflux SDK Versions page](https://docs.airflux.ai/sdk-release-note/ios-sdk-release-note).

   ```kotlin
   import ProjectDescription

   let project = Project(
       packages: [
           .remote(
               url: "https://github.com/ab180/airflux-ios-sdk-deployment",
               // Replace $HERE_LATEST_VERSION with latest version
               // - Example: requirement: .exact(from: "4.X.X")
               requirement: .exact(from: "$HERE_LATEST_VERSION")
           ),
           ...
       ],
       targets: [
           .target(
               dependencies: [
                   .package(product: "Airflux", type: .runtime),
                   ...
               ]
           ),
           ...
       ],
       ...
   )
   ```
3. Run the `tuist generate` command.
4. You can confirm that Airflux has been added to the **Package Dependencies** in Xcode.
   {% endtab %}

{% tab title="Manual Installation" %}
If you prefer a manual approach, you can directly download and add the SDK to your Xcode project.

1. Download the Airflux iOS SDK from the following URL:
   * [https://](https://sdk-internal.airbridge.io/build/airflux-ios-sdk/airflux-1.0.0-build-17/airflux-ios-sdk-deployment.zip)[sdk-download.airflux.ai/airflux-ios-sdk/latest/Airflux.zip](https://sdk-download.airflux.ai/airflux-ios-sdk/latest/Airflux.zip)
2. Unzip the file and find `Airflux.xcframework`.
3. In Xcode, go to your project file and navigate to the **\[General]** tab.
4. Scroll down to the **\[Frameworks, Libraries, and Embedded Content]** section and click the `+` button.
5. Click **\[Add Other...]**, then select **\[Add Files...]** and choose the `Airflux.xcframework` folder you downloaded.
6. Ensure that `Airflux.xcframework`'s Embed setting is configured to -`Embed & Sign`.
   {% endtab %}
   {% endtabs %}

***

## 2. SDK Initialization

Initialize the SDK by referring to the code below.&#x20;

{% hint style="info" %}
Your `YOUR_APP_NAME` and `YOUR_APP_SDK_TOKEN` credentials are available in the Airbridge dashboard via \[Settings] > \[Token Management].
{% endhint %}

<table><thead><tr><th>SDK Option</th><th width="216">Method</th><th>Data Type</th><th width="205.55078125">Description</th><th>Required</th></tr></thead><tbody><tr><td>App Name</td><td><code>AirfluxOptionBuilder()</code></td><td><code>string</code></td><td>Input the App Name from the Airbridge dashboard.</td><td><strong>Required</strong></td></tr><tr><td>App Token</td><td><code>AirfluxOptionBuilder()</code></td><td><code>string</code></td><td>Input the App Token from the Airbridge dashboard.</td><td><strong>Required</strong></td></tr><tr><td>SDK Enabled</td><td><code>setSDKEnabled()</code></td><td><code>boolean</code></td><td><p>Set whether to enable the SDK upon initialization.</p><ul><li><code>true</code>: The SDK is initialized in active mode.</li><li><code>false</code>: The SDK is initialized in inactive mode and is enabled upon calling the Airflux.<code>EnableSDK()</code>function.</li></ul></td><td>Optional</td></tr><tr><td>Auto Start Tracking Enabled</td><td><code>setAutoStartTrackingEnabled()</code></td><td><code>boolean</code></td><td><p>Set whether to collect events automatically upon SDK initialization.</p><ul><li><code>true</code>: Event collection starts automatically upon initialization.</li><li><code>false</code>: Event collection starts upon calling the <code>Airflux.StartTracking()</code> function.</li></ul></td><td>Optional</td></tr><tr><td>Log Level</td><td><code>setLogLevel()</code></td><td><code>AirfluxLogLevel</code></td><td>Set the log level for the Airflux SDK. Choose from <code>debug</code>, <code>info</code>, <code>warning</code>, <code>error</code>, <code>fault</code> .</td><td>Optional</td></tr><tr><td>Session Timeout</td><td><code>setSessionTimeout()</code></td><td><code>double</code></td><td>The default value is 300 seconds. Modify if needed.</td><td>Optional</td></tr><tr><td>Allow Every Country Enabled</td><td><code>setAllowEveryCountryEnabled()</code></td><td><code>boolean</code></td><td>When set to true, all countries are allowed to follow Airflux's optimization policies. To use a specific list of countries, set it to false and provide a list using <code>setCountryAllowlist()</code>.</td><td>Optional</td></tr><tr><td>Country Allowlist</td><td><code>setCountryAllowlist()</code></td><td><code>List&#x3C;String></code></td><td>Set the countries where calling the Airflux's inference API should be allowed. Use country codes following the ISO 3166-1 alpha-2 format (e.g., US, KR). You can set multiple countries using the Country Allowlist array. Airflux identifies a country based on the value tied to the device.</td><td>Optional</td></tr></tbody></table>

{% tabs %}
{% tab title="AppDelegate (Swift)" %}

```swift
import UIKit
import Airflux

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Creates the option for initializing the Airflux SDK.
        // Replace "YOUR_APP_NAME" and "YOUR_APP_TOKEN" with your actual credentials.
        let option = AirfluxOptionBuilder(name: "YOUR_APP_NAME", token: "YOUR_APP_TOKEN")
            // Automatically enables the SDK on startup.
            .setSDKEnabled(true)
            // Automatically starts tracking events.
            .setAutoStartTrackingEnabled(true)
            // Sets the log level to debug for detailed logs.
            .setLogLevel(AirfluxLogLevel.debug)
            // Sets the session timeout to 300 seconds (5 minutes).
            .setSessionTimeout(second: 300)
            // Allows Airflux features in all countries.
            .setAllowEveryCountryEnabled(true)
            // Uncomment the line below to allow only specific countries.
            // .setCountryAllowlist(["US", "KR", "JP"])
            .build()

        // Initializes the SDK with the configured option.
        Airflux.initializeSDK(option: option)
        
        return true
    }
}
```

{% endtab %}

{% tab title="AppDelegate (Objective-C)" %}

```objectivec
#import "AppDelegate.h"
#import <airflux/Airflux.h> 

@interface AppDelegate ()
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Creates the option for initializing the Airflux SDK.
    // Replace "YOUR_APP_NAME" and "YOUR_APP_TOKEN" with your actual credentials.
    AirfluxOptionBuilder *optionBuilder = [AirfluxOptionBuilder alloc] initWithName:@"YOUR_APP_NAME" token:@"YOUR_APP_TOKEN"];
    // Automatically enables the SDK on startup.
    [optionBuilder setSDKEnabled:YES];
    // Automatically starts tracking events.
    [optionBuilder setAutoStartTrackingEnabled:YES];
    // Sets the log level to debug for detailed logs.
    [optionBuilder setLogLevel:AirfluxLogLevelDebug];
    // Sets the session timeout to 300 seconds (5 minutes).
    [optionBuilder setSessionTimeoutWithSecond:300];
    // Allows Airflux features in all countries.
    [optionBuilder setAllowEveryCountryEnabled:YES];
    // Uncomment the line below to allow only specific countries.
    // [optionBuilder setCountryAllowlist:@[@"US", @"KR", @"JP"]];
    AirfluxOption *option = [optionBuilder build];

    // Initializes the SDK with the configured option.
    [Airflux initializeSDKWithOption:option];

    return YES;
}
```

{% endtab %}

{% tab title="SwiftUI (Swift)" %}

```swift
import SwiftUI
import Airflux

@main
struct YourApp: App {
    init() {
        // Creates the option for initializing the Airflux SDK.
        // Replace "YOUR_APP_NAME" and "YOUR_APP_TOKEN" with your actual credentials.
        let option = AirfluxOptionBuilder(name: "YOUR_APP_NAME", token: "YOUR_APP_TOKEN")
            // Automatically enables the SDK on startup.
            .setSDKEnabled(true)
            // Automatically starts tracking events.
            .setAutoStartTrackingEnabled(true)
            // Sets the log level to debug for detailed logs.
            .setLogLevel(AirfluxLogLevel.debug)
            // Sets the session timeout to 300 seconds (5 minutes).
            .setSessionTimeout(second: 300)
            // Allows Airflux features in all countries.
            .setAllowEveryCountryEnabled(true)
            // Uncomment the line below to allow only specific countries.
            // .setCountryAllowlist(["US", "KR", "JP"])
            .build()
        
        // Initializes the SDK with the configured option.
        Airflux.initializeSDK(option: option)
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
```

{% endtab %}
{% endtabs %}

***

## 3. Verification

#### **iOS Console Log Check**

To view detailed log information for your app in Xcode, use the following method before initializing the SDK

{% hint style="warning" %}
You can set the log output level using the `setLogLevel` function. Setting it to `AirfluxLogLevel.DEBUG` allows you to see all Airflux logs.
{% endhint %}

## 4. Frequently Asked Questions

{% hint style="info" %}
Opt-in policy compliance

If player consent is required to send in-game data, implement the necessary setup by following the FAQ section below.&#x20;

[How can I set up the Airflux SDK to comply with the opt-in policy?](https://docs.airflux.ai/airflux-onboarding/airflux-integration/2.-install-the-airflux-sdk#how-can-i-set-up-the-airflux-sdk-to-comply-with-the-opt-in-policy)
{% endhint %}

<details>

<summary>How can I set up the Airflux SDK to comply with the opt-in policy?</summary>

The opt-in policy requires user consent before collecting and using player data. To adhere to this policy, implement the following methods.

1. **SDK opt-in setup**

Upon initialization of the Airflux SDK, set the initialization option `setAutoStartTrackingEnabled()`to `false` and call the `startTracking()` function at the point where you have received user consent for data tracking. The Airflux SDK will collect data after the `startTracking()` function is called.

{% hint style="warning" %}
**Attention**

Although event data is not tracked before `startTracking()` is triggered and after `stopTracking()` is triggered, player attribute data is aggregated and anonymized for transmission upon calling the Inference API.
{% endhint %}

```csharp
// After player provided consent to data tracking
Airflux.startTracking()

// If player withdraws consent to data tracking
Airflux.stopTracking()
```

2. **Initializing the Airflux SDK in inactive mode**

{% hint style="warning" %}
**Attention**

If the SDK is not enabled immediately after the SDK initialization, the Install and Open events may not be collected.
{% endhint %}

Set the initialization option `setSDKEnabled()` to `false` to initialize the SDK with all functions disabled until user consent for data tracking is obtained. Through this method, you can adhere to privacy policies to the highest level. Note that when the SDK is set in inactive mode, all features are disabled and no events and player attribute data is sent to Airflux.

</details>

<details>

<summary>How can I configure the Airflux SDK to call the Inference API only in specific countries</summary>

Set the initialization opeion `setAllowEveryCountryEnabled()` to false and add the countries you want to allow to the "Country Allowlist". Country codes should follow the ISO 3166-1 alpha-2 format (e.g., "US", "KR"), and multiple countries can be specified by separating codes with commas. Country codes are not case-sensitive.

</details>

<details>

<summary>Can I use other mediation platforms, such as MAX and AdMob, with Airflux?</summary>

Yes, Airflux is designed to work alongside existing mediation platforms.

</details>

<details>

<summary>How does Airflux determine a user’s country?</summary>

Airflux distinguishes a country based on the value tied to the deivce.

</details>

<details>

<summary>Does Airflux collect the ADID (Advertising ID)?</summary>

No. The Airflux SDK operates without collecting or requiring the ADID.

</details>
