Video Interstitial

Video ads are full-screen videos that appear inside your application.

1. Load the video

Navigate to the header file that you want the video to appear in (e.g. MyViewController.h/ViewController.swift) and add the following import statement at the top of the file:

Objective-C
Swift
#import <Tapdaq/Tapdaq.h>

@interface MyViewController : UIViewController <TapdaqDelegate, TDAdRequestDelegate>

The above code imports Tapdaq to the class, and declares that we will conform to the TapdaqDelegate protocol.

You only need to provide import statement once per header file.

Next, add the following command to the implementation file (e.g. MyViewController.m/ViewController.swift) inside a method of your choice:

Objective-C
Swift
- (void)viewDidLoad {
    [super viewDidLoad];
    [[Tapdaq sharedSession] setDelegate:self];
}

Once this is done, the Tapdaq delegate method -didLoadConfig becomes available, implement it like so:

Objective-C
Swift
- (void)didLoadConfig {
    [[Tapdaq sharedSession] loadVideoForPlacementTag:@"my_video_tag" delegate:self];
}

This delegate method is invoked when the Tapdaq SDK has finished loading it's config, and is ready to begin loading ads.

Delegate parameter must conform to TDAdRequestDelegate.

Ads should only be requested once the Tapdaq delegate method -didLoadConfig has been called. This ensures Tapdaq is initialised and ready to begin loading ads. Requesting ads prior to Tapdaq initialising will result in failed ad requests

2. Display the video

Once that is done, implement the following:

Objective-C
Swift
- (void)didLoadAdRequest:(TDAdRequest *)adRequest {
    if ([adRequest isKindOfClass:[TDMediationAdRequest class]] && [adRequest.placement.tag isEqualToString:@"my_video_tag"]) {
        if (adRequest.placement.adTypes & TDAdTypeVideo) {
            [(TDMediationAdRequest *)adRequest display];
        }
    }
}

The code above is executed when the video has successfully loaded. For a full list of video delegate methods we support, see our Callbacks page.

It is also possible to check the video is loaded before displaying it to the user, as shown below:

Objective-C
Swift
if ([[Tapdaq sharedSession] isVideoReadyForPlacementTag:@"my_video_tag"]) {
    [[Tapdaq sharedSession] showVideoForPlacementTag:@"my_video_tag"];
}

3. Load another video on close

If you wish to load another video after you have shown one, implement one of the following options:

A. Auto Reload all Ads

To auto reload all ads using the same placement tag, set the global config before initializing, like so:

Objective-C
Swift
TDProperties *properties = [[TDProperties alloc] init];
[properties setAutoReloadAds:YES];

B. Implement the didCloseVideo Delegate with the placement tag you'd like to reload

When loading an video interstitial ad the delegate specified in the loadVideo can conform to TDDisplayableAdRequestDelegate which will allow it to handle didCloseAdRequest:.

Objective-C
Swift
- (void)didCloseAdRequest:(TDAdRequest *)adRequest {
    [[Tapdaq sharedSession] loadVideoForPlacementTag:adRequest.placement.tag delegate:self];
}

Build and run your application to test the advert displays correctly.

Note: We strongly advise against trying to show a video ad on application launch.

Need help?

If you are having any problems integrating, feel free to contact us on [email protected] and we will be more than happy to help.

What's next?

Now that you have successfully integrated a video into your app, what would you like to do next?