You have different ways to display ads. Please find below three cases that cover most class integrations.

Case 1: Display as soon as possible

A classic implementation is to present the ad when your app becomes active. Just be sure to check that an ad is available, and none is currently displayed.

- (void)applicationDidBecomeActive:(UIApplication *)application {

    // check if there is an ad available, and that none is currently displayed
    if ([AppsfireAdSDK isThereAModalAdAvailableForType:AFAdSDKModalTypeSushi forZone:@"ZONE_ID"] == AFAdSDKAdAvailabilityYes && ![AppsfireAdSDK isModalAdDisplayed]) {

            // delay a bit the request because ‘applicationDidBecomeActive:’ could prevent a part of the animation
            double delayInSeconds = 0.5;
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                [AppsfireAdSDK requestModalAd:AFAdSDKModalTypeSushi forZone:@"ZONE_ID" withController:[UIApplication sharedApplication].keyWindow.rootViewController withDelegate:nil];
            });

    }

}

And we recommend that you add the similar code whenever the delegate method -modalAdsRefreshedAndAvailable is called. That way you can be sure an ad is available.

- (void)modalAdsRefreshedAndAvailable {

    // check if there is an ad available, and that none is currently displayed
    if ([AppsfireAdSDK isThereAModalAdAvailableForType:AFAdSDKModalTypeSushi] == AFAdSDKAdAvailabilityYes && ![AppsfireAdSDK isModalAdDisplayed]) {

            [AppsfireAdSDK requestModalAd:AFAdSDKModalTypeSushi withController:[UIApplication sharedApplication].keyWindow.rootViewController withDelegate:nil];

    }

}

You can of course decide to display the ad in a more subtle way, as presented in Case 2 below.

Case 2: Display in a breakout session

A breakout session is a natural “break” in the user experience of your app. It’s a good way to display ads if you don’t want to bother your users too much.

Examples of breakout sessions:

  • In any app

    • When you just provided a service to your user
    • When the user is waiting for content to be loaded (locally or from your web-services)

  • In a game app

    • When there is a gameover
    • When the user finished a level

Like the code you saw above, you don’t have much to write! We suggest that you create a method that you’ll be able to call from different places of your application. Then, it’s up to you to call the method when you decide it should be a good time.

- (BOOL)displayModalAdIfPossible {

    // if there is no ad or if one is already displayed, stop there!
    if ([AppsfireAdSDK isThereAModalAdAvailableForType:AFAdSDKModalTypeSushi forZone:@"ZONE_ID"] != AFAdSDKAdAvailabilityYes || [AppsfireAdSDK isModalAdDisplayed])
            return NO;

    // else, request the ad that should quickly appears
    [AppsfireAdSDK requestModalAd:AFAdSDKModalTypeSushi forZone:@"ZONE_ID" withController:[UIApplication sharedApplication].keyWindow.rootViewController withDelegate:nil];

    return YES;

}

This example returns a boolean that you can use to know if an ad is going to be displayed.

Case 3: Use a timer to inform an ad is coming

For Uramaki you may want to use a (visual) timer which will warn the users that an ad is going be displayed.

Visual timer

This is a good approach if you want to:

  • Have a 'smoother' transition from your app to an ad, if you think that directly showing the ad would negatively impact the user experience
  • Allow the user to skip the ad

We only recommend this for the Uramaki format. The implementation is very simple. Just include the helper class AppsfireAdTimerView (which can be found in the demo project) and call the ad like this:

if ([AppsfireAdSDK isThereAModalAdAvailableForType:AFAdSDKModalTypeUraMaki forZone:@"ZONE_ID"] == AFAdSDKAdAvailabilityYes) {

    [[[AppsfireAdTimerView alloc] initWithCountdownStart:3] presentWithCompletion:^(BOOL accepted) {

        if (accepted)
            [AppsfireAdSDK requestModalAd:AFAdSDKModalTypeUraMaki forZone:@"ZONE_ID" withController:[UIApplication sharedApplication].keyWindow.rootViewController withDelegate:nil];

    }];

}
If your project isn't using ARC, please don't forget to set the -fobjc-arc flag on the AppsfireAdTimerView.m file, and release the class in the completion block to avoid a leak.