Wiki

Clone wiki

App Open Ad Sample iOS / Home

Welcome

Index:

  1. Project Setup
  2. AATKit initialisation
  3. Consent handling
  4. App Open Integration
  5. AATKit 3 App Open Migration (beta)
  6. Sample App

App Open Integration

Starting from AATKit v2.74.0. we introduced a new format called AppOpen

App open ads are a special ad format (created by Google) intended for publishers wishing to monetize their app load 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.

It works like the fullscreen Placament but with some key differences:

Creating App Open Placement

one of the main differences is that you need to create the placement as soon as the app become active in applicationDidBecomeActive method in your AppDelegate, to create a App Open placement call the following:

Swift

let appOpenPlacement = AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>")
Objective-C:
id appOpenPlacement = [self createAppOpenAdPlacement:@"<PLACEMENT_NAME>"];

Note: You need to use a dedicated placement name for the App-Open placement other than the fullscreen placement.

Loading App Open Placement

After creating the placement you need to start placement AutoReloading to get Ad as soon as possiple

Swift

func applicationDidBecomeActive(_ application: UIApplication) {
    // start loading Ads as soon as app become active
    // set placement viewController
    AATKit.setPlacementViewController(self.window?.rootViewController, for: placement)

    // start placement autoreloading each 60s
    AATKit.startPlacementAutoReload(withSeconds: 60, for: placement)
}
Objective-C
-(void)applicationDidBecomeActive:(UIApplication *)application {
    // start loading Ads as soon as app become active
    // set placement viewController
    [AATKit setPlacementViewController:self.window.rootViewController forPlacement: placement];

    // start placement autoreloading each 60s
    [AATKit startPlacementAutoReloadWithSeconds:60 forPlacement:placement];
}

Loading Ads on Loading Screen

App Open Placement are meant to monitize your App Loading screen, so the most proper place to display the Ad is in your own LoadingViewController, so while the user are waiting your App for being ready to use, if AATkit has succeffully obtained an Ad you should display it before sending the user to the main content. to do so you will need your AppDelegate to conform to AATKitDelegate protocol

Swift

extension AppDelegate: AATKitDelegate {
    func aatKitHaveAd(_ placement: AATKitPlacement) {
        // AATKit got an Ad
        // sending notification to all other insterested parties with that event
        NotificationCenter.default.post(name: NSNotification.Name("aatKitHaveAd"), object: placement)
    }
}

Objective-C

-(void)AATKitHaveAd:(NSObject<AATKitPlacement> *)placement {
    // AATKit got an Ad
    // sending notification to all other insterested parties with that event
    [[NSNotificationCenter defaultCenter] postNotificationName:@"aatKitHaveAd" object:placement];
}

and in your LoadingViewController you need to start listening for that event and show the App-Open Ad

Swift

class LoadingViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self,
                                               selector: #selector(didReceiveAd),
                                               name: Notification.Name("aatKitHaveAd"),
                                               object: nil)
    } 

    @objc func didReceiveAd() {
        // check if Loading isn't finished and the loading screen is still on screen
        guard isLoading,
            let placement = appOpenPlacement 
        else { return }

        // stop listeneing to new Ad notifications
        NotificationCenter.default.removeObserver(self, name: .init("aatKitHaveAd"), object: nil)

        // displaying The App open Ad
        AATKit.show(placement)
    }   
}

Objective-C

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didReceiveAds)
                                                 name:@"aatKitHaveAd"
                                               object:nil];
}

-(void) didReceiveAds {
    // check if Loading isn't finished and the loading screen is still on screen
    if (self.isLoading == false) {
        return;
    }

    // stop listeneing to new Ad notifications
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    // displaying The App open Ad
    [AATKit showPlacement:placement];
}

After the user close the Ad you should send the user to your app main content, you will get notified when the fullscreen ad is closed in func aatKitResume(afterAd placement: AATKitPlacement?) delegate method.

Loading Ads on app foregrounding events

and the other way to use the App Open placement is when your app enters foreground, This can be done by overriding the applicationDidBecomeActive: method in your AppDelegate.

in applicationDidBecomeActive: method you need to check if AATkit has an App Open Ad then display it so applicationDidBecomeActive: would look like:

  func applicationDidBecomeActive(_ application: UIApplication) {
        // start loading Ads as soon as app become active
        guard let placement = self.appOpenPlacement else { return }

        // set placement viewController
        AATKit.setPlacementViewController(self.window?.rootViewController, for: placement)

        // start placement autoreloading each 60s
        AATKit.startPlacementAutoReload(withSeconds: 60, for: placement)


        if AATKit.haveAd(for: appOpenPlacement) {
            // display loadedFullscreen ad if available
            AATKit.show(appOpenPlacement)
        }
    }

Objective-C

-(void)applicationDidBecomeActive:(UIApplication *)application {
    // start loading Ads as soon as app become active
    // set placement viewController
    [AATKit setPlacementViewController:self.window.rootViewController forPlacement: placement];

    // start placement autoreloading each 60s
    [AATKit startPlacementAutoReloadWithSeconds:60 forPlacement:placement];

    if ([AATKit haveAdForPlacement:placement]) {
        [AATKit showPlacement:placement];
    }
}

Sample App

Updated