Check if a modal ad is available

An ad won't necessarily be available as soon as the SDK is initialized. The library will need to sync with our servers. So before you request an ad, you should check its availability! There is a simple way to do that.

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

    // sushi ad is available

}

Here ZONE_ID is the zone ID for your Sushi (interstitial) ads as provided by Appsfire.

The method +isThereAModalAdAvailableForType: is returning an ENUM called AFAdSDKAdAvailability. You can make the distinction between three cases:

  • AFAdSDKAdAvailabilityPending: anwser can't be given right now
  • AFAdSDKAdAvailabilityYes: an ad is available right now
  • AFAdSDKAdAvailabilityNo: no ad is available right now

If you want to be alerted of the availability of a modal ad when your app is launching, you could use the AppsfireAdSDK delegate!

Don't forget to set the delegate if you plan using this method!
- (void)modalAdsRefreshedAndAvailable {

    // a sushi or uramaki ad is available

}

Request a modal ad

Once you know a modal ad is available, you can request it via +requestModalAd:forZone:withController:withDelegate: method.

+ (void)requestModalAd:(AFAdSDKModalType)modalType forZone:(NSString *)zoneId withController:(UIViewController *)controller withDelegate:(id<AFAdSDKModalDelegate>)delegate;

zoneId : ID of zone that contains the ad, as supplied by Appsfire
modalType: allows you to choose the modal type (see above for the two available formats, Sushi & Uramaki).
controller: allows to specify the host view controller to present the ad, and eventually the store kit.
delegate: (optional) allows to specify a delegate to get specific events.

The method is asynchronous. You may request an ad to present itself as soon as possible. Or you may wait for an ad to be available, and present it almost right away.

Let's say you are in a breakout session, you could request an ad this way:

// ad is available
ìf ([AppsfireAdSDK isThereAModalAdAvailableForType:AFAdSDKModalTypeSushi forZone:@"ZONE_ID"] == AFAdSDKAdAvailabilityYes) {

    // request it
    [AppsfireAdSDK requestModalAd:AFAdSDKModalTypeSushi forZone:@"ZONE_ID" withController:[UIApplication sharedApplication].keyWindow.rootViewController withDelegate:nil];

}

// ad isn't available yet
else {

    // continue normal behavior

}

Force the dismissal of a modal ad

You can force the dismissal of a modal ad when one ad is displayed. It should be use in a critical state only.
Note that any modal ad is dismissed when app goes into background.

This method returns YES if a modal ad was dismissed, NO otherwise.

// [...]

[AppsfireAdSDK forceDismissalOfModalAd];

// [...]
In the majority of cases, you shouldn't use this method. We highly recommend not to use this method if you aren't sure of the results.
Please refer to the documentation or contact us if you have any doubt!