# App Open

The app open ads are a special format which main purpose is to allow the monetization of the app load screens.

These ads can be closed anytime and are meant to be shown when the app moves to foreground.

## **Integration**

This ad format can be only integrated through code, by implementing any of the two possible ways of integration that are described below.

### **Manual**

In this kind of integration, it is needed to create an instance of the `WAAppOpenAd` class and use the `loadAd()` and `showAd()` methods to make the ad load and show on demand. The publisher is the responsible of deciding when the ad must be shown and implement the required logic.

Below you can find a simple integration example:

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

```swift
import UIKit
import WortiseSDK

class ViewController: UIViewController {

    private var appOpenAd: WAAppOpenAd!

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        appOpenAd = WAAppOpenAd(adUnitId: "test-app-open")
        appOpenAd.loadAd()
    }

    override func willMove(toParent controller: UIViewController?) {
        super.willMove(toParent: controller)
        ...
        appOpenAd.destroy()
    }
    
    func showAppOpen() {
        if appOpenAd.isAvailable {
            appOpenAd.showAd(from: self)
        }
    }
}
```

{% endtab %}
{% endtabs %}

Also, the `WAAppOpenAd` class offers the following additional methods to configure its behaviour:

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

```swift
// Sets if a new ad must be loaded after closing the previous one
appOpenAd.autoReload = true

// Shows an ad immediately if available. Otherwise, requests the load of a
// new ad
appOpenAd.tryToShowAd(from: self)
```

{% endtab %}
{% endtabs %}

### **Via Manager**

The SDK provides a standard implementation of App Open to facilitate the integration of this ad format.

To perform this kind of integration, it is needed to create an instance of `WAAppOpenManager` inside the `AppDelegate` class, just as shown in the example below:

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

```swift
import UIKit
import WortiseSDK

class AppDelegate: UIResponder, UIApplicationDelegate {

    private var appOpenManager: WAAppOpenManager!

    func application(_
        application: UIApplication, didFinishLaunchingWithOptions
        launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        ...
        appOpenManager = WAAppOpenManager(adUnitId: "test-app-open")
        appOpenManager.loadAd()
    }
}
```

{% endtab %}
{% endtabs %}

With this simple integration, the app will show ads every time there is a transition from background to foreground.

Also, the `WAAppOpenManager` class offers the same methods as `WAAppOpenAd` to configure its behavior and show ads on demand.

## Delegate **configuration**

Like occurs with other formats, a delegate can be set to receive the events that happen during the ad lifecycle. For this, it is needed to implement the `WAAppOpenDelegate` interface just as shown in the example below:

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

```swift
extension AppDelegate : WAAppOpenDelegate {
    
    func didClick(appOpenAd: WAAppOpenAd) {
        // Invoked when the ad has been clicked
    }

    func didDismiss(appOpenAd: WAAppOpenAd) {
        // Invoked when the ad has been dismissed
    }
    
    func didFailToLoad(appOpenAd: WAAppOpenAd, error: WAAdError) {
        // Invoked when the ad could not be loaded
        // (because of an error or no fill)
    }

    func didFailToShow(appOpenAd: WAAppOpenAd, error: WAAdError) {
        // Invoked when the ad could not be shown
    }

    func didImpress(appOpenAd: WAAppOpenAd) {
        // Invoked when the ad has generated an impression
    }

    func didLoad(appOpenAd: WAAppOpenAd) {
        // Invoked when the ad has been loaded
    }
    
    func didPayRevenue(appOpenAd: WAAppOpenAd, data: WARevenuedata) {
        // Invoked when the ad has generated revenue
    }
 
    func didShow(appOpenAd: WAAppOpenAd) {
        // Invoked when the ad has been shown
    }
}
```

Once the interface is implemented, the delegate is assigned to the ad instance:

```swift
appOpenAd.delegate = self
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wortise.com/en/ios-sdk/sdk-integration/app-open.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
