AppOpen (Google)

Integrate AppOpen ads

App open ads are a special fullscreen ad format (created by Google) intended for publishers wishing to monetize their app loading screens (“splash screens”). App open ads can be closed at any time, and are designed to be shown when your users bring your app to the foreground.

Create Placement

You need to create the AppOpen placement as soon as the app becomes active in the applicationDidBecomeActive() method in your AppDelegate.

To create an instance of AATAppOpenAdPlacement, use the following API:

var placement = AATSDK.createAppOpenAdPlacement(placementName: "<PLACEMENT_NAME>")

Listen to Callbacks (Optional)

Through the use of AATAppOpenPlacementDelegate, you can listen to the different placement callbacks.

placement.delegate = self

Request Ad (In AppDelegate)

After creating the placement you need to start placement auto-reloading to get an ad as soon as possible.

func applicationDidBecomeActive(_ application: UIApplication) {
    // Start loading Ads as soon as app become active
    guard let placement = self.placement else { return }
    
    // Set placement viewController
    AATSDK.controllerViewDidAppear(controller: <ROOT_VIEW_CONTROLLER>)
    
    // Start placement autoreloading
    placement.startAutoReload()
}

Request Ad (In Loading Screen)

App Open Placement is meant to monetize your App Loading screen, so the most proper place to display the Ad is in your own LoadingViewController, so while the user is waiting for your App to be ready to use. If AATKit has successfully obtained an Ad you should display it before sending the user to the main content. To do so you will need your LoadingViewController to conform to the AATAppOpenPlacementDelegate protocol:

class LoadingViewController: UIViewController {
    // Create the placement
    var placement = AATSDK.createAppOpenAdPlacement(name: "<PLACEMENT_NAME>")
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // [IMPORTANT] Notify AATKit about the currently active view controller
        AATSDK.controllerViewDidAppear(controller: self)
        
        // Set placement delegate to listen to the callbacks
        placement.delegate = self
        
        // Start autoreloading the placement.
        placement.startAutoReload()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // [IMPORTANT] Remove the currently active view controller
        AATSDK.controllerViewWillDisappear()
        // [IMPORTANT] Stop placement autoreload
        placement?.stopAutoReload()
    }
}

extenstion LoadingViewController: AATAppOpenPlacementDelegate {
    func aatHaveAd(placement: AATPlacement) {
        // The placement has loaded a new ad
    }

    func aatNoAd(placement: AATPlacement) {
        // The placement could not load a new ad
    }
    
    func aatAdCurrentlyDisplayed(placement: AATPlacement) {
        // Ad has been displayed on the screen
    }

    func aatResumeAfterAd(placement: AATPlacement) {
        // Back to the app
    }
}

After the user closes the Ad you should send the user to your app's main content, you will get notified when the fullscreen ad is closed in func aatResumeAfterAd(placement: AATPlacement) delegate method.

Display Ad

You should display that ad at the start of the app session by calling show() method. If the AppOpen placement has a ready ad, It will present it.

placement.show()

Complete Code Example

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?

    var placement = AATSDK.createAppOpenAdPlacement(placementName: "<PLACEMENT_NAME>")
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        // AATKit initialization
        let configuration = AATConfiguration()
        AATSDK.initAATKit(with: configuration)
        return true
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
        // Start loading Ads as soon as app become active
        guard let placement = self.placement else { return }
        
        // Pass the root view controller to AATKit
        AATSDK.controllerViewDidAppear(controller: <ROOT_VIEW_CONTROLLER>)
        
        // Start placement autoreloading
        placement.startAutoReload()
        
        // display loaded ad if available
        placement.show()
    }
    
    func applicationWillResignActive(_ application: UIApplication) {
        // disable placement autoreloading
        placement?.stopAutoreloading()
    }
}

Loading Screen

The above code example assumes that you only show app open ads when users foreground your app after it is suspended in memory. So, if the user launches the app either for the first time since booting or after killing the application, the app will never have a ready ad.

In this case, it’s preferred to use a loading screen (that might be used to load your assets) and only show the ad from the loading screen (Only if the ad is ready and the loading screen is still active) to avoid surprising the user with an ad while using your app.

If you have a loading screen under the app open ad, and your loading screen completes loading before the ad is dismissed, you may want to dismiss your loading screen in the func aatResumeAfterAd() callback of the AATAppOpenPlacementDelegate.

Last updated