Ad callbacks

Before you start to set up your ads, it is important to understand the ad callbacks available in the AwesomeAds SDK.

Banner ads, interstitial ads, and video ads all send a number of callbacks to notify you of important lifecycle events, enabling you to perform specific actions when those events occur.

For example, you can use the adLoaded callback to play an ad as soon as it is loaded. Alternatively, you might wish to run some other custom code when you get the adLoaded callback.

Callbacks versus methods

In some situations, you may need to choose between using a callback or a method. In general, it is recommended that you use a callback when you need to respond immediately to an event.

For example, to play an ad, you can use either the adLoaded callback or the HasAdAvailable method.

  • If you want to play the ad as soon as it is loaded, it is recommended that you use the adLoaded callback.
  • If you want to load the ad at one point (for example, when the game starts) but not play it until some later stage, use the HasAdAvailable method.

For more information, see banner ad, interstitial ad, video ad.

Also see the examples:

AwesomeAds ad callbacks

These are all the ad callbacks available in the AwesomeAds SDK:

VideoAd.setCallback { [weak self] placementId, event in
    switch event {
    case .adLoaded:
        // called when an ad has finished loading

    case .adEmpty:
        // called when the request was successful but the ad server returned no ad

    case .adFailedToLoad:
        // called when an ad could not be loaded

    case .adAlreadyLoaded:
        // called when the ad was previously loaded for the given creativeId

    case .adShown:
        // called when an ad is first shown

    case .adFailedToShow:
        // called when an ad fails to show

    case .adClicked:
        // called when an ad is clicked

    case .adEnded:
        // called when a video ad has ended playing (but hasn't yet closed)

    case .adClosed:
        // called when a fullscreen ad is closed

    case .adPaused:
        // called when the video ad is paused

    case .adPlaying:
        // called when the video ad starts or resumes playing
    }
}
[SAVideoAd setCallback:^(NSInteger placementId, SAEvent event) {
    switch (event) {
        case SAEventAdLoaded: {
            // called when an ad has finished loading
            break;
        }
        case SAEventAdEmpty: {
            // called when the request was successful but the ad server returned no ad
            break;
        }
        case SAEventAdFailedToLoad: {
            // called when an ad could not be loaded
            break;
        }
        case SAEventAdAlreadyLoaded: {
            // called when the ad was previously loaded for the given creativeId
            break;
        }
        case SAEventAdShown: {
            // called when an ad is first shown
            break;
        }
        case SAEventAdFailedToShow: {
            // called when an ad fails to show
            break;
        }
        case SAEventAdClicked: {
            // called when an ad is clicked
            break;
        }
        case SAEventAdEnded: {
            // called when a video ad has ended playing (but hasn't yet closed)
            break;
        }
        case SAEventAdClosed: {
            // called when a fullscreen ad is closed
            break;
        }
        case SAEventAdPaused: {
            // called when the video ad is paused
            break;
        }
        case SAEventAdPlaying: {
            // called when the video ad starts or resumes playing
            break;
        }
    }
}];