Guide
Native cross-promo
Load a native placement and show it. The SDK slides up a banner for one of your other games, in your game's colors, at the bottom of the screen. You do not place or size it.
What the banner is #
A native banner, centered on the bottom safe-area edge. It shows one of your other games: icon, name, one line, and an arrow. A cut-out from that game sits at the top-left corner and a close button at the top-right. Both rise a little above the banner.
| Phone | Tablet | |
|---|---|---|
| Size | 320 × 100 dp | 728 × 180 dp |
| Maximum height, from the bottom safe-area edge | 133 dp | 236 dp |
| Used when | any other window, a phone in landscape included | the window is at least 744 dp wide and its shorter side at least 600 dp |
The size is chosen at show, from the window then, and kept until the banner closes. The banner's bottom edge sits on the bottom safe-area edge (Android: the window's bottom system-bar inset; iOS: the safe area's bottom), and the cut-out rises above it, 33 dp on the phone size and 56 dp on the tablet size: the banner reaches 133 dp or 236 dp above that edge, and its soft shadow a few dp more. It is centered, 320 or 728 dp wide, and the cut-out and the close reach about 10 dp past its sides. The phone-size banner keeps 8 dp from the window's sides where the window has room; on a window under 336 dp wide that margin shrinks, to none at 320 dp, and the cut-out and the close move in just enough that the window's edge never cuts them. On iOS the same numbers are points.
Keeping that area clear at the break is your layout. The SDK does not move, shrink or report the banner, and nothing of your game's sits there while it shows: a bottom bar, a button row or a banner ad's 50 dp slot is shorter than the banner and would be covered. Lay the screen out so that whatever the player must see or tap at that moment ends above the height in the table.
- It slides up in 300 ms and slides back down when it closes; with the system's reduce-motion setting on, it fades in and out in place instead.
- A tap anywhere on the banner opens the promoted game's store page (on iOS, as a sheet over your game). Taps in the first 300 ms after it lands do nothing.
- A tap opens nothing on a game not on a store yet or on one already installed on the device: only your test devices are shown either, never a player's.
- The close button is its own target, 48 dp square, and always works. A touch outside the banner and its close reaches your game.
- Your code never names a game: it loads a placement, and NGA's server picks which of your other games with Promoted on fills it each time.
Where the banner may show #
The banner draws over whatever is at the bottom of the screen, and it cannot be moved. Nothing of your game's sits there while it shows:
- Show it only where the bottom is empty: game over, level complete, pause, or a menu with its buttons higher up. The area is the height to keep clear, across the full width.
- Your own banner ad steps aside through the banner yield: the SDK hides it just before NGA's banner draws and shows it again when the show ends. Register the yield once; your banner ad then needs no other rule. Covering a network's banner would break its policies.
- Close it first (
close(), UnityClose()) before you put anything of your own there: a "continue" bar, a keyboard, a panel.
One banner shows at a time in your app.
Players who should not see it #
In two cases, do not load the native placement; keep your own content in that slot:
- A player who bought remove-ads. The banner carries the AD label, so a player who paid to see no ads should not see it. Full-screen backfill needs nothing: NGA's ad is loaded only where your mediation's would have been shown, so your game's own remove-ads rule covers those moments.
- A game running in another language. The banner's text is English-only in this release.
The examples below check both before they load.
Your own banner ad #
If your game shows a banner ad of its own, register a banner yield once, at start: two callbacks the SDK runs around every native banner show. A game with no banner ad registers none.
| The SDK | Your code | |
|---|---|---|
hide |
called once per show, on the main thread (Unity: the game thread), just before NGA's banner is added, once the show's other checks have passed. The banner follows one frame later, so your layout settles first | hides the banner ad's view and pauses its refresh. The ad stays loaded: never destroy or reload it for this |
restore |
called exactly once for each hide, after NGA's banner is removed, whatever ended the show: the player's close, your close(), the screen going away, the window shrinking, or a hide that failed |
shows the banner ad again and resumes its refresh, if your game still wants the banner there. Resume refresh whenever the banner is allowed now, not only when it was refreshing at hide |
- A tap on NGA's banner opens the store over your game and leaves the banner up; your banner ad stays hidden until the show ends.
- A
hidethat throws (in Unity: throws, or is not back within a second) refuses the show:onShowFailedwithINVALID_SHOW_TARGET / show.target.yield_failed, the ad staysREADY, andrestoreis still called. A throw fromrestoreis not caught: it is your game's. - Register it once, right after
initialize, withsetBannerYield; the pair is held until a later call replaces it. Bothnullclears it; onenullalone is ignored with a warning. A registration beforeinitializeis kept too. - With no yield registered, the first native show in the process logs one
WARN,NGACrossPromo: no banner yield registered, and NGA's banner draws over whatever is there. A game that shows no banner ad can ignore that line. - Unity.
hideruns on the game thread and the SDK waits for it at most a second: hide the banner and pause its refresh, nothing else.
One example per mediation and engine. Each keeps your game's own banner pauses apart from the yield, in one small class: a resume of your game's cannot bring the banner ad back while NGA's banner is up, and a banner ad created during a yield starts hidden and paused.
AppLovin MAX
Unity (C#)
using System;
using NGA;
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the game.
public sealed class MaxBannerYield
{
readonly string adUnitId; // your MAX banner ad unit
readonly Func<bool> wanted; // your game's own answer: the banner belongs on this screen right now
public MaxBannerYield(string adUnitId, Func<bool> wanted) { this.adUnitId = adUnitId; this.wanted = wanted; }
// NGA's banner is up and the banner ad is out of its way. While it is true, your own code does not call ShowBanner.
public bool Yielded { get; private set; }
// Register once, right after NGASDK.Initialize.
public void Register() => NGASDK.SetBannerYield(Hide, Restore);
// The SDK, on the game thread, just before NGA's banner draws. Not guarded: a throw here must reach the SDK, which refuses the show.
void Hide()
{
Yielded = true;
MaxSdk.HideBanner(adUnitId);
MaxSdk.StopBannerAutoRefresh(adUnitId); // the ad stays loaded, never destroyed or reloaded for this
}
// The SDK, once per Hide, when the show ends, however it ended.
void Restore()
{
if (!Yielded) return;
Yielded = false;
MaxSdk.StartBannerAutoRefresh(adUnitId); // refresh resumes whatever the banner's state at Hide
if (wanted()) MaxSdk.ShowBanner(adUnitId); // and it is shown again if your game still wants it there
}
}
Android (Kotlin)
import android.view.View
import com.applovin.mediation.ads.MaxAdView
import network.nga.sdk.NGASDK
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the app.
class MaxBannerYield {
private var banner: MaxAdView? = null
// NGA's banner is up and the banner ad is out of its way.
var yielded = false
private set
// Your game's own wish: refresh, unless it paused the banner (MAX's banner refreshes from its first load).
private var refreshWanted = true
// Register once, right after NGASDK.initialize.
fun register() = NGASDK.setBannerYield(Runnable { hide() }, Runnable { restore() })
// Your banner ad's view when you create it, null when you destroy it. A view attached during a yield starts hidden and paused.
fun attach(view: MaxAdView?) {
banner = view
if (view != null && yielded) {
view.visibility = View.GONE
view.stopAutoRefresh()
}
}
// Your game's own pauses, kept apart from the yield: the Activity going to the background, the banner no longer allowed.
fun pause() {
refreshWanted = false
banner?.stopAutoRefresh()
}
fun resume() {
refreshWanted = true
if (!yielded) banner?.startAutoRefresh() // while yielded, the banner stays paused until restore
}
// The SDK, on the main thread, just before NGA's banner draws.
private fun hide() {
yielded = true
banner?.let {
it.visibility = View.GONE
it.stopAutoRefresh() // the ad stays loaded, never destroyed or reloaded for this
}
}
// The SDK, once per hide, when the show ends, however it ended.
private fun restore() {
if (!yielded) return
yielded = false
banner?.let {
it.visibility = View.VISIBLE
if (refreshWanted) it.startAutoRefresh() // refresh resumes if your game wants the banner now
}
}
}
iOS (Swift)
import UIKit
import AppLovinSDK
import NGASDK
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the app.
final class MaxBannerYield {
private var banner: MAAdView?
// NGA's banner is up and the banner ad is out of its way.
private(set) var yielded = false
// Your game's own wish: refresh, unless it paused the banner (MAX's banner refreshes from its first load).
private var refreshWanted = true
// Register once, right after NGASDK.initialize.
func register() {
NGASDK.setBannerYield(hide: { [weak self] in self?.hide() }, restore: { [weak self] in self?.restore() })
}
// Your banner ad's view when you create it, nil when you remove it. A view attached during a yield starts hidden and paused.
func attach(_ view: MAAdView?) {
banner = view
if let view, yielded {
view.isHidden = true
view.stopAutoRefresh()
}
}
// Your game's own pauses, kept apart from the yield: the app going to the background, the banner no longer allowed.
func pause() {
refreshWanted = false
banner?.stopAutoRefresh()
}
func resume() {
refreshWanted = true
if !yielded { banner?.startAutoRefresh() } // while yielded, the banner stays paused until restore
}
// The SDK, on the main thread, just before NGA's banner draws.
private func hide() {
yielded = true
banner?.isHidden = true
banner?.stopAutoRefresh() // the ad stays loaded, never destroyed or reloaded for this
}
// The SDK, once per hide, when the show ends, however it ended.
private func restore() {
guard yielded else { return }
yielded = false
banner?.isHidden = false
if refreshWanted { banner?.startAutoRefresh() } // refresh resumes if your game wants the banner now
}
}
Unity LevelPlay
Unity (C#)
using System;
using NGA;
using Unity.Services.LevelPlay;
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the game.
public sealed class LevelPlayBannerYield
{
readonly Func<bool> wanted; // your game's own answer: the banner has loaded and belongs on this screen right now
LevelPlayBannerAd banner; // your banner ad, from Attach
public LevelPlayBannerYield(Func<bool> wanted) { this.wanted = wanted; }
// NGA's banner is up and the banner ad is out of its way. While it is true, your own code does not call ShowAd.
public bool Yielded { get; private set; }
// Register once, right after NGASDK.Initialize.
public void Register() => NGASDK.SetBannerYield(Hide, Restore);
// Your banner ad when you create it, null when you destroy it. A banner made during a yield starts hidden and paused.
public void Attach(LevelPlayBannerAd ad)
{
banner = ad;
if (ad == null || !Yielded) return;
ad.HideAd();
ad.PauseAutoRefresh();
}
// The SDK, on the game thread, just before NGA's banner draws. Not guarded: a throw here must reach the SDK, which refuses the show.
void Hide()
{
Yielded = true;
if (banner == null) return;
banner.HideAd();
banner.PauseAutoRefresh(); // the ad stays loaded, never destroyed or reloaded for this
}
// The SDK, once per Hide, when the show ends, however it ended.
void Restore()
{
if (!Yielded) return;
Yielded = false;
if (banner == null) return;
banner.ResumeAutoRefresh(); // refresh resumes whatever the banner's state at Hide
if (wanted()) banner.ShowAd(); // and it is shown again if your game still wants it there
}
}
Android (Kotlin)
import android.view.View
import com.unity3d.mediation.banner.LevelPlayBannerAdView
import network.nga.sdk.NGASDK
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the app.
class LevelPlayBannerYield {
private var banner: LevelPlayBannerAdView? = null
// NGA's banner is up and the banner ad is out of its way.
var yielded = false
private set
// Your game's own wish: refresh, unless it paused the banner (LevelPlay's banner refreshes from its first load).
private var refreshWanted = true
// Register once, right after NGASDK.initialize.
fun register() = NGASDK.setBannerYield(Runnable { hide() }, Runnable { restore() })
// Your banner ad's view when you create it, null when you destroy it. A view attached during a yield starts hidden and paused.
fun attach(view: LevelPlayBannerAdView?) {
banner = view
if (view != null && yielded) {
view.visibility = View.GONE
view.pauseAutoRefresh()
}
}
// Your game's own pauses, kept apart from the yield: the Activity going to the background, the banner no longer allowed.
fun pause() {
refreshWanted = false
banner?.pauseAutoRefresh()
}
fun resume() {
refreshWanted = true
if (!yielded) banner?.resumeAutoRefresh() // while yielded, the banner stays paused until restore
}
// The SDK, on the main thread, just before NGA's banner draws.
private fun hide() {
yielded = true
banner?.let {
it.visibility = View.GONE
it.pauseAutoRefresh() // the ad stays loaded, never destroyed or reloaded for this
}
}
// The SDK, once per hide, when the show ends, however it ended.
private fun restore() {
if (!yielded) return
yielded = false
banner?.let {
it.visibility = View.VISIBLE
if (refreshWanted) it.resumeAutoRefresh() // refresh resumes if your game wants the banner now
}
}
}
iOS (Swift)
import UIKit
import IronSource
import NGASDK
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the app.
final class LevelPlayBannerYield {
private var banner: LPMBannerAdView?
// NGA's banner is up and the banner ad is out of its way.
private(set) var yielded = false
// Your game's own wish: refresh, unless it paused the banner (LevelPlay's banner refreshes from its first load).
private var refreshWanted = true
// Register once, right after NGASDK.initialize.
func register() {
NGASDK.setBannerYield(hide: { [weak self] in self?.hide() }, restore: { [weak self] in self?.restore() })
}
// Your banner ad's view when you create it, nil when you remove it. A view attached during a yield starts hidden and paused.
func attach(_ view: LPMBannerAdView?) {
banner = view
if let view, yielded {
view.isHidden = true
view.pauseAutoRefresh()
}
}
// Your game's own pauses, kept apart from the yield: the app going to the background, the banner no longer allowed.
func pause() {
refreshWanted = false
banner?.pauseAutoRefresh()
}
func resume() {
refreshWanted = true
if !yielded { banner?.resumeAutoRefresh() } // while yielded, the banner stays paused until restore
}
// The SDK, on the main thread, just before NGA's banner draws.
private func hide() {
yielded = true
banner?.isHidden = true
banner?.pauseAutoRefresh() // the ad stays loaded, never destroyed or reloaded for this
}
// The SDK, once per hide, when the show ends, however it ended.
private func restore() {
guard yielded else { return }
yielded = false
banner?.isHidden = false
if refreshWanted { banner?.resumeAutoRefresh() } // refresh resumes if your game wants the banner now
}
}
Google AdMob
Unity (C#)
using System;
using GoogleMobileAds.Api;
using NGA;
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the game.
public sealed class AdMobBannerYield
{
readonly Func<bool> wanted; // your game's own answer: the banner has loaded and belongs on this screen right now
BannerView banner; // your banner ad, from Attach
public AdMobBannerYield(Func<bool> wanted) { this.wanted = wanted; }
// NGA's banner is up and the banner ad is out of its way. While it is true, your own code does not call Show.
public bool Yielded { get; private set; }
// Register once, right after NGASDK.Initialize.
public void Register() => NGASDK.SetBannerYield(Hide, Restore);
// Your banner ad when you create it, null when you destroy it. A banner made during a yield starts hidden.
public void Attach(BannerView ad)
{
banner = ad;
if (ad != null && Yielded) ad.Hide();
}
// The SDK, on the game thread, just before NGA's banner draws. Not guarded: a throw here must reach the SDK, which refuses the show.
// Hide() also pauses the AdView on Android; on iOS the plugin has no pause, and hiding is all there is to do.
void Hide()
{
Yielded = true;
banner?.Hide(); // the ad stays loaded, never destroyed or reloaded for this
}
// The SDK, once per Hide, when the show ends, however it ended.
void Restore()
{
if (!Yielded) return;
Yielded = false;
if (banner != null && wanted()) banner.Show(); // shown again if your game still wants it there
}
}
Android (Kotlin)
import android.view.View
import com.google.android.gms.ads.AdView
import network.nga.sdk.NGASDK
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the app.
class AdMobBannerYield {
private var banner: AdView? = null
// NGA's banner is up and the banner ad is out of its way.
var yielded = false
private set
// Your game's own wish: refresh, unless it paused the banner (AdMob's banner refreshes from its first load).
private var refreshWanted = true
// Register once, right after NGASDK.initialize.
fun register() = NGASDK.setBannerYield(Runnable { hide() }, Runnable { restore() })
// Your banner ad's view when you create it, null when you destroy it. A view attached during a yield starts hidden and paused.
fun attach(view: AdView?) {
banner = view
if (view != null && yielded) {
view.visibility = View.GONE
view.pause()
}
}
// Your game's own pauses, kept apart from the yield: the Activity going to the background, the banner no longer allowed.
fun pause() {
refreshWanted = false
banner?.pause()
}
fun resume() {
refreshWanted = true
if (!yielded) banner?.resume() // while yielded, the banner stays paused until restore
}
// The SDK, on the main thread, just before NGA's banner draws.
private fun hide() {
yielded = true
banner?.let {
it.visibility = View.GONE
it.pause() // stops its refresh; the ad stays loaded, never destroyed or reloaded for this
}
}
// The SDK, once per hide, when the show ends, however it ended.
private fun restore() {
if (!yielded) return
yielded = false
banner?.let {
it.visibility = View.VISIBLE
if (refreshWanted) it.resume() // refresh resumes if your game wants the banner now
}
}
}
iOS (Swift)
import UIKit
import GoogleMobileAds
import NGASDK
// Your banner ad's side of the yield, beside the code that owns the banner ad. One instance for the app.
final class AdMobBannerYield {
private var banner: BannerView?
// NGA's banner is up and the banner ad is out of its way.
private(set) var yielded = false
// Register once, right after NGASDK.initialize.
func register() {
NGASDK.setBannerYield(hide: { [weak self] in self?.hide() }, restore: { [weak self] in self?.restore() })
}
// Your banner ad's view when you create it, nil when you remove it. A view attached during a yield starts hidden.
func attach(_ view: BannerView?) {
banner = view
if yielded { view?.isHidden = true }
}
// The SDK, on the main thread, just before NGA's banner draws. AdMob's iOS banner has no refresh pause: hiding it is all there is to do.
private func hide() {
yielded = true
banner?.isHidden = true // the ad stays loaded, never destroyed or reloaded for this
}
// The SDK, once per hide, when the show ends, however it ended.
private func restore() {
guard yielded else { return }
yielded = false
banner?.isHidden = false
}
}
The calls each mediation gives, which the examples use and nothing else:
| Mediation | hide |
restore |
|---|---|---|
| AdMob | Android: AdView to GONE, pause(). iOS: BannerView.isHidden. Unity: BannerView.Hide(), which pauses the AdView on Android |
Android: VISIBLE, resume(). iOS: isHidden = false. Unity: Show() |
| LevelPlay | Android LevelPlayBannerAdView, iOS LPMBannerAdView: hidden, pauseAutoRefresh(). Unity LevelPlayBannerAd: HideAd(), PauseAutoRefresh() |
shown, resumeAutoRefresh(). Unity: ResumeAutoRefresh(), ShowAd() |
| MAX | Android MaxAdView, iOS MAAdView: hidden, stopAutoRefresh(). Unity: MaxSdk.HideBanner, StopBannerAutoRefresh |
shown, startAutoRefresh(). Unity: StartBannerAutoRefresh, ShowBanner |
What the banner shows #
- Your game's style. The banner takes your game's colors, read from its store listing (or draft listing) at registration. On some native Android games it also takes the shape of the game's own panels and buttons; every other game gets NGA's standard banner in its colors, and a game whose colors NGA cannot read gets NGA's default style.
- Before NGA first reads your game's listing, its native placements get
NO_FILL.
| Text | Comes from | Limit |
|---|---|---|
| Name | the Short name you gave in the portal, else the store title | a short name is at most 20 characters; a longer name is cut with an ellipsis |
| Line | one of the copy lines you approved under Creatives; with none approved, "name — Play now" | 50 characters |
The text is in the system font, in English, left to right.
Load and show #
Load when the screen opens. When onLoaded is called, call show with the screen: on Android the Activity, on iOS the view controller, in Unity nothing. A load that finds no ad calls onFailed, and the bottom of the screen stays empty.
- One-screen games. If a level's end is a moment, not a screen, call
loadAdat that moment andshowinonLoaded. Ignore anonLoadedthat arrives after the moment has passed. With Prefetch on,onLoadedis called immediately, with an ad already loaded. - Which view controller (iOS). Pass the one that shows your game. In SpriteKit, Metal or a single-scene game this is usually the key window's root view controller. In SwiftUI it is the
UIHostingControllerthat hosts your game's view.
Unity (C#)
using UnityEngine;
using NGA;
// On your game-over screen's root object. Nothing else is at the bottom of this screen.
public class GameOverScreen : MonoBehaviour, NGAAdLoadCallback, NGAAdShowListener
{
const string GameOverPromo = "plc_example_native";
NGAAd promoAd; // from its load until its show ends
void OnEnable()
{
if (RemoveAdsOwned() || !GameInEnglish()) return; // see Players who should not see it
NGASDK.LoadAd(GameOverPromo, this);
}
// The banner stays on screen across your scenes and panels until it is closed.
void OnDisable() { ClosePromo(); }
// Call this before your game shows anything of its own at the bottom of the screen.
public void ClosePromo() { promoAd?.Close(); }
// NGAAdLoadCallback
public void OnLoaded(NGAAd ad)
{
// promoAd is kept after a refused show, and the next LoadAd hands back that same ad: show it again.
if (this == null || !isActiveAndEnabled || (promoAd != null && promoAd != ad) || !ad.IsReady()) return;
promoAd = ad;
ad.Show(this); // the SDK adds the banner over the bottom of the screen and slides it up
}
public void OnFailed(string placementId, NGAError error) { } // no fill: the bottom stays empty
public void OnExpired(NGAAd ad)
{
if (promoAd != null && promoAd.OpportunityId == ad.OpportunityId) promoAd = null;
}
// NGAAdShowListener
public void OnShowStarted(NGAAd ad) { } // the impression counted
public void OnClicked(NGAAd ad) { } // the store is opening
public void OnRewardResult(NGAAd ad, NGARewardResult result) { } // never for the banner
public void OnCompleted(NGAAd ad, NGAShowCompletion completion) { }
public void OnClosed(NGAAd ad) { promoAd = null; } // the player's close, Close(), or the screen going away
public void OnShowFailed(NGAAd ad, NGAError error)
{
if (!ad.IsReady()) promoAd = null; // a refused show leaves the ad ready: the next OnEnable shows it
}
// Your game's own code.
bool RemoveAdsOwned() { return false; }
bool GameInEnglish() { return true; }
}
Android (Kotlin)
import android.app.Activity
import android.os.Bundle
import network.nga.sdk.NGAAd
import network.nga.sdk.NGAAdLoadCallback
import network.nga.sdk.NGAAdShowListener
import network.nga.sdk.NGAError
import network.nga.sdk.NGASDK
import network.nga.sdk.NGAShowCompletion
// Your game-over screen. Nothing else is at the bottom of its layout.
class GameOverActivity : Activity(), NGAAdLoadCallback, NGAAdShowListener {
private var promoAd: NGAAd? = null // from its load until its show ends
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(…): your game-over layout
if (removeAdsOwned() || !gameInEnglish()) return // see Players who should not see it
NGASDK.loadAd(GAME_OVER_PROMO, this)
}
override fun onResume() {
super.onResume()
promoAd?.takeIf { it.isReady() }?.show(this, this) // a show refused while this screen was paused
}
// Call this before your game shows anything of its own at the bottom of the screen.
fun closePromo() {
promoAd?.close() // slides the banner down; onClosed follows
}
// NGAAdLoadCallback
override fun onLoaded(ad: NGAAd) {
if (isDestroyed || promoAd != null || !ad.isReady()) return
promoAd = ad
ad.show(this, this) // the SDK adds the banner over the bottom of this screen and slides it up
}
override fun onFailed(placementId: String, error: NGAError) {} // no fill: the bottom stays empty
override fun onExpired(ad: NGAAd) {
if (promoAd === ad) promoAd = null
}
// NGAAdShowListener
override fun onShowStarted(ad: NGAAd) {} // the impression counted
override fun onCompleted(ad: NGAAd, completion: NGAShowCompletion) {}
override fun onClosed(ad: NGAAd) { // the player's close, close(), or this screen going away
if (promoAd === ad) promoAd = null
}
override fun onShowFailed(ad: NGAAd, error: NGAError) {
if (promoAd === ad && !ad.isReady()) promoAd = null // a refused show leaves the ad ready: onResume shows it
}
// Your game's own code.
private fun removeAdsOwned(): Boolean = false
private fun gameInEnglish(): Boolean = true
companion object {
const val GAME_OVER_PROMO = "plc_example_native"
}
}
iOS (Swift)
import UIKit
import NGASDK
// Your game-over screen. Nothing else is at the bottom of its view.
final class GameOverViewController: UIViewController, NGAAdLoadCallback, NGAAdShowListener {
private static let gameOverPromo = "plc_example_native"
private var promoAd: NGAAd? // from its load until its show ends
override func viewDidLoad() {
super.viewDidLoad()
// Your game-over content goes here.
if removeAdsOwned() || !gameInEnglish() { return } // see Players who should not see it
NGASDK.loadAd(Self.gameOverPromo, callback: self)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let ad = promoAd, ad.isReady { ad.show(from: self, listener: self) } // loaded before this screen was on screen
}
// Call this before your game shows anything of its own at the bottom of the screen.
func closePromo() {
promoAd?.close() // slides the banner down; onClosed follows
}
// NGAAdLoadCallback
func onLoaded(_ ad: NGAAd) {
guard isViewLoaded, promoAd == nil, ad.isReady else { return }
promoAd = ad
ad.show(from: self, listener: self) // the SDK adds the banner over the bottom of this view and slides it up
}
func onFailed(placementId: String, error: NGAError) {} // no fill: the bottom stays empty
func onExpired(_ ad: NGAAd) {
if promoAd === ad { promoAd = nil }
}
// NGAAdShowListener
func onShowStarted(_ ad: NGAAd) {} // the impression counted
func onCompleted(_ ad: NGAAd, completion: NGAShowCompletion) {}
func onClosed(_ ad: NGAAd) { // the player's close, close(), or this screen going away
if promoAd === ad { promoAd = nil }
}
func onShowFailed(_ ad: NGAAd, error: NGAError) {
if promoAd === ad && !ad.isReady { promoAd = nil } // a refused show leaves the ad ready: viewDidAppear shows it
}
// Your game's own code.
private func removeAdsOwned() -> Bool { false }
private func gameInEnglish() -> Bool { true }
}
A screen that cannot present yet. show needs the screen in front. Otherwise it fails with ACTIVITY_NOT_RESUMED, the ad stays READY, and you show it again when the screen is back, as onResume and viewDidAppear do above. Every refusal is in Show lifecycle.
The examples register the screen as the load callback, so the SDK can keep a closed screen in memory for up to 30 minutes if its ad is never shown. That is harmless for most games; to avoid it, see Callback ownership.
Unity. The banner is added over the Unity player's view, above all Unity UI, and Unity's Activity and view controller last the whole game: the banner stays on screen across your scenes and panels until it is closed. Close it when you leave the screen you showed it on, as OnDisable does above. Keep Render Over Native UI off; the build check enforces it.
Single-Activity games (Android). If your screens are Compose destinations or fragments in one Activity, the Activity does not go away with the screen, so neither does the banner. Close it when the screen leaves (for example, when its composable leaves the composition), as the Unity example does in OnDisable.
The banner and a full-screen ad on one screen #
If one screen shows the banner and runs full-screen backfill, give each its own callback object: the backfill examples keep theirs in InterstitialBackfill and RewardedBackfill, so the screen itself can be the banner's, as above. Or keep one set of callbacks and branch on ad.placementId. An object declared inside the screen holds the screen as the screen itself would; an app-wide object does not.
When both come at one moment, such as a level's end, show the full-screen ad first and the banner after its onClosed: a banner cannot open over a full-screen ad (see Show lifecycle).
Show lifecycle #
The show callbacks, for the banner:
| Callback | When |
|---|---|
onShowStarted |
the impression counted: once the banner has landed, at least half of it visible for a second, its screen in front and the device's screen on |
onClicked |
each tap on the banner (it opens the store). A tap before the impression counts the impression first |
onCompleted(COMPLETED), then onClosed |
the show ended after its impression |
onClosed alone |
the show ended before its impression counted |
onShowFailed |
the show could not start; error says why, and nothing follows |
The banner never gets onRewardResult. Every show ends exactly once, with one onClosed or one onShowFailed; the full order is on Callbacks.
When show is refused, onShowFailed is called and the ad stays READY. Show it again when the cause is gone:
| Cause | Error | Show again when |
|---|---|---|
| The screen is not in front (Android: the Activity not resumed, or finishing; iOS: the view controller not in a window or presenting something, or the app not active), or a full-screen ad is in front | ACTIVITY_NOT_RESUMED / show.activity.not_resumed |
the screen is back (onResume, viewDidAppear, as in the examples), or the full-screen ad has closed |
| Another banner is on screen | ALREADY_SHOWING / show.already_showing.banner |
that banner has closed |
| The window is under 320 × 133 dp (the phone size's banner, and the cut-out above it), such as a narrow split-screen | INVALID_SHOW_TARGET / show.target.window_too_small |
the window is bigger |
Your banner yield's hide threw (in Unity: threw, or was not back within a second). restore was called |
INVALID_SHOW_TARGET / show.target.yield_failed |
hide is fixed; the ad stays ready |
A loaded banner can start showing for 30 minutes. After that it has expired, isReady() is false, and show fails with EXPIRED: load again. See NGAAd.
While it shows:
| Event | Result |
|---|---|
| The player taps the banner | the store opens over your game; the banner stays up, and your banner ad stays hidden |
The player taps the close, or you call close() |
the show ends; the banner slides down and is removed, and your banner ad is restored. close() on an ad that is not showing does nothing |
| Its screen goes away: on Android the Activity is destroyed, a system recreate included; on iOS the view controller is dismissed, popped or released | the show ends with onClosed. A recreated screen loads a new banner |
| The window shrinks below 320 × 133 dp, for example into a split-screen half | the show ends |
| A rotation or resize, on iOS or on an Android Activity that handles its own configuration changes (Unity's does) | the banner moves to the new bottom center, at the size it started with |
| Another screen or a full-screen ad covers it | the banner waits underneath, and its impression timer pauses |
| It has been on screen a long time | nothing: expiry applies only before the show starts |
For the next banner, call loadAd again with a callback; the shown ad has released the old one. With Auto-reload on, the SDK loads the next ad as soon as a show ends, so on a screen that stays open the next loadAd gets its onLoaded immediately. Caps keep it in bounds (by default 3 banners a session and 10 a day per placement, see Caps); at a cap, loads fail with NO_FILL / no_fill.cap.
Next #
Add full-screen backfill, or test the banner on a registered device.