> For the complete documentation index, see [llms.txt](https://aatkit.gitbook.io/ios-integration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aatkit.gitbook.io/ios-integration/start/initialization.md).

# Initialization

### Configure AATKit

Before loading ads, the app must initialize AATKit first. This only needs to be done once per app session, ideally at the app launch. You should call the `initAATKit(with configuration: AATConfiguration?)` as early as possible to ensure optimal ad performance.

Call the initialization method with an [AATConfiguration](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatconfiguration) instance which contains the necessary configuration data needed to initialize AATKit. Through [AATDelegate](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatdelegate), you can listen to AATKit callbacks such as obtaining mediation rules from the backend or unknown bundleID events.

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

```swift
let configuration = AATConfiguration()
configuration.delegate = self
AATSDK.initAATKit(with: configuration)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
AATConfiguration *configuration = [[AATConfiguration alloc] init];
configuration.delegate = self;
[AATSDK initAATKitWith:configuration];
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can add some extra configurations for some ad networks using [AATAdNetworksOptions](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatadnetworksoptions). For more information, see [Ad Networks](/ios-integration/ad-networks.md) section.
{% endhint %}

### Reconfigure AATKit

AATKit enables reconfiguring it at runtime. This might be needed for some cases like reacting to consent changes or geo-location settings changes. To reconfigure AATKit, use the reconfigure public API passing an instance of [AATRuntimeConfiguration](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatruntimeconfiguration).

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

```swift
let newConfiguration = AATRuntimeConfiguration()
newConfiguration.consentRequired = true
newConfiguration.consent = AATSimpleConsent(nonIABConsent: .obtained)
newConfiguration.isUseGeoLocation = true
AATSDK.reconfigure(configuration: newConfiguration)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
AATRuntimeConfiguration *newConfiguration = [[AATRuntimeConfiguration alloc] init];
newConfiguration.consentRequired = YES;
newConfiguration.consent = [[AATSimpleConsent alloc] initWithNonIABConsent:NonIABConsentObtained];
newConfiguration.isUseGeoLocation = YES;
[AATSDK reconfigureWithConfiguration:newConfiguration];code b
```

{% endtab %}
{% endtabs %}

### Test Mode

AATKit’s test mode provides ads even before your app has been set up at Gravite. This is convenient for testing your integration Please use your `testModeAccountId` to activate the test mode. Set the `testModeAccountId` in your [AATConfiguration](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatconfiguration) object. The `testModeAccountId` will be sent to you via email after registering at [Gravite](https://dashboard.addapptr.com/register).

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

```swift
let configuration = AATConfiguration()
configuration.delegate = self
configuration.testModeAccountId = <TEST_MODE_ID>
AATSDK.initAATKit(with: configuration)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
AATConfiguration *configuration = [[AATConfiguration alloc] init];
configuration.delegate = self;
configuration.testModeAccountId = <TEST_MODE_ID>;
[AATSDK initAATKitWith:configuration];
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Make sure to remove the `testModeAccountId` from your `AATConfiguration` object, before you publish your app to the AppStore. Otherwise, your app will not earn any ad revenue.
{% endhint %}

### Using an Alternative bundle ID

Gravite recognizes and identifies your app using its bundle ID. Should you need to use a different bundle ID for publishing or testing or other purposes, you can override the default bundle ID of your app by setting an "alternative bundle ID" for the [AATConfiguration](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatconfiguration) object. But: before you can use the alternative bundle ID properly, please make sure that our [support](mailto:support@gravite.net) has set up your app for the alternative bundle ID, as this is not a standard procedure.

AATKit will do dashboard reporting using your alternative bundle ID by default if you set it.

If for any reason reporting should still be done using your app's real bundle Id, you can set the `shouldReportUsingAlternativeBundleId` property of the [AATConfiguration](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatconfiguration) object to false.

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

```swift
configuration.alternativeBundleId = "com.alternativeBundleID"

// if you still need to report on the physical bundleID call this:
// configuration.shouldReportUsingAlternativeBundleId = false
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
configuration.alternativeBundleId = @"com.alternativeBundleID";

// if you still need to report on the physical bundleID call this:
// configuration.shouldReportUsingAlternativeBundleId = NO;
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
If you decide to use an alternative bundle ID, please contact our [support](mailto:support@gravite.net).
{% endhint %}

### Handling (multiple) View Controllers

Set the currently active view controller for AATKit before requesting ads from placements. You should set the view controller in your view controller `viewDidAppear(_ animated: Bool)` lifecycle method.

{% hint style="info" %}
Placements will not start loading ads before having the current view controller passed to AATKit.
{% endhint %}

**Set the Current View Controller**

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

```swift
AATSDK.controllerViewDidAppear(controller: self)
```

{% endtab %}

{% tab title="Objective-C" %}

```
[AATSDK controllerViewDidAppearWithController:self];
```

{% endtab %}
{% endtabs %}

**Remove the Current View Controller**

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

```swift
AATSDK.controllerViewWillDisappear()
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[AATSDK controllerViewWillDisappear];
```

{% endtab %}
{% endtabs %}

### Log Levels

AATKit supports the following log levels:

**Verbose**

Verbose-level messages are intended to capture **verbose**, **debug**, **info**, **warning** and **error** messages. It’s convenient in an intensive development environment.

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

```swift
AATSDK.setLogLevel(logLevel: .verbose)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[AATSDK setLogLevelWithLogLevel:AATLogLevelVerbose];
```

{% endtab %}
{% endtabs %}

Debug

Debug-level messages are intended to capture **debug**, **info**, **warning** and **error** messages. It’s convenient in a normal development environment.

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

```swift
AATSDK.setLogLevel(logLevel: .debug)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[AATSDK setLogLevelWithLogLevel:AATLogLevelDebug];
```

{% endtab %}
{% endtabs %}

**Info**

Info-level messages are intended to capture **info**, **warning** and **error** messages. Info-level may be helpful but isn’t enough for troubleshooting.

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

```swift
AATSDK.setLogLevel(logLevel: .info)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[AATSDK setLogLevelWithLogLevel:AATLogLevelInfo]
```

{% endtab %}
{% endtabs %}

**Warn**

Warn-level messages are intended to capture **warning** and **error** messages only.

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

```swift
AATSDK.setLogLevel(logLevel: .warn)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[AATSDK setLogLevelWithLogLevel:AATLogLevelWarn];
```

{% endtab %}
{% endtabs %}

**Error**

Error-level messages are intended to capture **error** messages only.

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

```swift
AATSDK.setLogLevel(logLevel: .error)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[AATSDK setLogLevelWithLogLevel:AATLogLevelError];
```

{% endtab %}
{% endtabs %}
