Wiki

Clone wiki

App Open Ad Sample iOS / AATKit 3 App Open Migration

  1. App Open Integration
  2. Sample App

App Open Integration

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:

Instead of:

Swift

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

Use:

Swift

let appOpenPlacement = AATSDK.createAppOpenAdPlacement(placementName: "<PLACEMENT_NAME>")
Objective-C:
id<AATAppOpenAdPlacement>  appOpenPlacement = [AATSDK createAppOpenAdPlacementWithPlacementName:@"<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

Instead of:

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];
}

Use:

Swift

func applicationDidBecomeActive(_ application: UIApplication) {
    // start loading Ads as soon as app become active
    startAutoreloading()


    if let appOpenPlacement = self.appOpenPlacement, 
        appOpenPlacement.hasAd()  {
            // display loadedFullscreen ad if available
            appOpenPlacement.show()
    }
}

func startAutoreloading() {
    guard let placement = self.appOpenPlacement,
          let viewController = self.window?.rootViewController
    else { return }

    // set placement viewController
    AATSDK.controllerViewWillAppear(controller: viewController)

    // start placement autoreloading each 60s
    placement.startAutoReload()
}
Objective-C
-(void)applicationDidBecomeActive:(UIApplication *)application {
  // start loading Ads as soon as app become active
  [self startAutoreloading];

  if ([appOpenPlacement hasAd]) {
      [appOpenPlacement show];
  }
}

- (void)startAutoreloading {
    // set placement viewController
    [AATSDK controllerViewWillAppearWithController:<VIEW_CONTROLLER>];

    // start placement autoreloading each 60s
    [self.appOpenPlacement startAutoReload];
}

Loading Ads on Loading Screen

App Open Placement are 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 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 LoadingViewController to conform to AATAppOpenPlacementDelegate protocol

Swift

 func aatAdCurrentlyDisplayed() {
        /// This method will be called with the ad display event
    }

    func aatResumeAfterAd() {
        /// This method will be called when the app resumes after  displaying an ad
    }

    func aatHaveAd() {
       /// This method will be called when there is an ad
       // show the placement
        AATSDK.showPlacement(placement: appOpenPlacement)
    }

    func aatNoAd() {
        /// This method will be called when there is no ad available
    }

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 aatResumeAfterAd() 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

    AATSDK.controllerViewWillAppear(controller: <viewController>)

    // start placement autoreloading each 60s
    placement.startAutoReload()


    if appOpenPlacement.hasAd() {
        // display loadedFullscreen ad if available
        appOpenPlacement.show()
    }
}

Objective-C

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // start loading Ads as soon as app become active
    // set placement viewController
    [AATSDK controllerViewWillAppearWithController: <viewController];

    // start placement autoreloading each 60s
    [appOpenPlacement startAutoReload];

    if ([appOpenPlacement hasAd]) {
        [appOpenPlacement show];
    }
}

Sample App

Updated