Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Implementation for Interstitial Video ads

funakoshi-dev edited this page Mar 6, 2023 · 24 revisions

Preparation

Please refer to the link below if you have not downloaded the SDK or created an ad space.

Integrating the SDK

If you have not added the SDK into the Project, please add it by the following methods.

Implementation

Implementation of interstitial video ad will be done with the following six steps.

NADInterstitialVideoDelegate

It conforms to the NADInterstitialVideoDelegate protocol to receive event notifications.

Swift
import NendAd

class ViewController: UIViewController, NADInterstitialVideoDelegate {
    ...
}
Objective-C
@import NendAd;

@interface ViewController : UIViewController <NADInterstitialVideoDelegate>

...

@end

Create an instance

First, generate the instance of NendAdInterstitialVideo.
Set delegate to receive event notifications.

Swift
// Keep instance
private let interstitialVideo = NADInterstitialVideo(spotID: spotID, apiKey: "apiKey")
...

self.interstitialVideo.delegate = self
Objective-C
@property (nonatomic) NADInterstitialVideo *interstitialVideo;

...

self.interstitialVideo = [[NADInterstitialVideo alloc] initWithSpotID:spotID apiKey:@"apiKey"];
self.interstitialVideo.delegate = self;

The information necessary for instance creation is as follows.

Argument Type Description
spotID NSInteger SpotID issued by management page of nend
apiKey NSString ApiKey issued by management page on nend

Load Video Ad

Load the ad by loadAd.

Swift
self.interstitialVideo.loadAd()
Objective-C
[self.interstitialVideo loadAd];

The load result is reported by NADInterstitialVideoDelegate.

Show Video Ad

Show the ad by showAd after confirmed that loading of ad is completed by isReady .

The ViewController set in the parameter must be placed correctly on the UIWindow hierarchy. (The self example below is a subclass of UIViewController.)

Swift
if self.interstitialVideo.isReady {
    self.interstitialVideo.showAd(from: self)
}
Objective-C
if (self.interstitialVideo.isReady) {
    [self.interstitialVideo showAdFromViewController:self];
}

Release Video Ad

Discard video ads that are no longer needed.

Swift
self.interstitialVideo.releaseAd()
Objective-C
[self.interstitialVideo releaseVideoAd];

Implementation Optional Functions

Please implement the following option as necessary.

Set mute state to play video

Set mute to play video using isMuteStartPlaying property.
And default value is true.

Swift
self.interstitialVideo.isMuteStartPlaying = false
Objective-C
self.interstitialVideo.isMuteStartPlaying = NO;

Display Fullscreen Ads

If you can not display interstitial video for reasons such as out of stock, you can display fullscreen ads on full screen instead. In order to use this function, you need to register ad space of fullscreen ads separately on the management screen.

Swift
self.interstitialVideo.addFallbackFullboard(withSpotID: spotID, apiKey: "apiKey")
Objective-C
[self.interstitialVideo addFallbackFullboardWithSpotID:spotID apiKey:@"apiKey"];

Fullscreen Ad's background color outside Safe Area

You can change the Fullscreen Ad's background color outside iPhoneX Safe Area more affinitive to your app looking & feeling.

Swift
self.interstitialVideo.fallbackFullboardBackgroundColor = UIColor.white
Objective-C
self.interstitialVideo.fallbackFullboardBackgroundColor = [UIColor whiteColor];

Receive notification

You can use NADInterstitialVideoDelegate to receive notification about each process of interstitial video.

⚠️Notice about ads callback⚠️
Interactive ads (NADVideoAdTypePlayable) can't receive messages from a Delegate when the video ads were played or stopped or finished.

Normal Video ads (NADVideoAdTypeNormal) can use Delegate to receive messages when the video ads were played or stopped or finished.

Interactive ads (NADVideoAdTypePlayable) is not video but working on the WebView.
Because of that, Interactive ads can't receive messages from a Delegate when the video ads were played or stopped or finished.

loading of ad is completed

Swift
func nadInterstitialVideoAdDidReceiveAd(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Receive.")
}
Objective-C
- (void)nadInterstitialVideoAdDidReceiveAd:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Receive.");
}

You can get ad type information by adType property.

adType Description
NADVideoAdTypeNormal Normal video ads
NADVideoAdTypePlayable User-controllable ads
Swift
func nadInterstitialVideoAdDidReceiveAd(_ nadInterstitialVideoAd: NADInterstitialVideo!) {
    var adType: String
    switch nadInterstitialVideoAd.adType {
    case .normal:
        adType = "normal"
    case .playable:
        adType = "playable"
    default:
        adType = "unknown"
    }
    print(#function + " : Ad Type = " + adType)
}
Objective-C
- (void)nadInterstitialVideoAdDidReceiveAd:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSString *adType;
    switch (nadInterstitialVideoAd.adType) {
        case NADVideoAdTypeNormal:
            adType = @"normal";
            break;
        case NADVideoAdTypePlayable:
            adType = @"playable";
            break;
        default:
            adType = @"unknown";
            break;
    }
    NSLog(@"%s : Ad Type = %@", __FUNCTION__, adType);
}

loading of ad is failed

Swift
func nadInterstitialVideoAd(_ nadInterstitialVideoAd: NADInterstitialVideo!, didFailToLoadWithError error: Error!)
{
    print("Interstitial Video Did Fail to Receive. error: \(error!)")
}
Objective-C
- (void)nadInterstitialVideoAd:(NADInterstitialVideo *)nadInterstitialVideoAd didFailToLoadWithError:(NSError *)error
{
    NSLog(@"Interstitial Video Did Fail to Receive. error: %@", error);
}

Error code at load failure is as follows.

Code Description
204 No delivery ads
400 BAD request
5XX Server error
600 Error in SDK
601 Ad download failed
602 Fallback fullscreen ad failed
603 Invalid network
604 Advertisement acquisition network error (timeout etc.)
605 Received invalid response data

playing of video is failed

Swift
func nadInterstitialVideoAdDidFailed(toPlay nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Fail to Show.")
}
Objective-C
- (void)nadInterstitialVideoAdDidFailedToPlay:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Fail to Show.");
}

ad shown

Swift
func nadInterstitialVideoAdDidOpen(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Open.")
}
Objective-C
- (void)nadInterstitialVideoAdDidOpen:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Open.");
}

video started (Never called on NADVideoAdTypePlayable)

Swift
func nadInterstitialVideoAdDidStartPlaying(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Start Playing.")
}
Objective-C
- (void)nadInterstitialVideoAdDidStartPlaying:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Start Playing.");
}

video stopped (Never called on NADVideoAdTypePlayable)

Swift
func nadInterstitialVideoAdDidStopPlaying(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Stop Playing.")
}
Objective-C
- (void)nadInterstitialVideoAdDidStopPlaying:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Stop Playing.");
}

video completed playing to the end (Never called on NADVideoAdTypePlayable)

Swift
func nadInterstitialVideoAdDidCompletePlaying(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Complete Playing.")
}
Objective-C
- (void)nadInterstitialVideoAdDidCompletePlaying:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Complete Playing.");
}

ad closed

Swift
func nadInterstitialVideoAdDidClose(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Close.")
}
Objective-C
- (void)nadInterstitialVideoAdDidClose:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Close.");
}

ad clicked

Swift
func nadInterstitialVideoAdDidClickAd(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Click Ad.")
}
Objective-C
- (void)nadInterstitialVideoAdDidClickAd:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Click Ad.");
}

information button clicked

Swift
func nadInterstitialVideoAdDidClickInformation(_ nadInterstitialVideoAd: NADInterstitialVideo!)
{
    print("Interstitial Video Did Click Information.")
}
Objective-C
- (void)nadInterstitialVideoAdDidClickInformation:(NADInterstitialVideo *)nadInterstitialVideoAd
{
    NSLog(@"Interstitial Video Did Click Information.");
}

Verification

In the test mode of video advertisement, it is necessary to register IDFA(Advertising Identifier) of the device on the management screen of nend.

How to check IDFA

IDFA value will be printed in debug logs when SDK Log level set over Info & created NADInterstitialVideo object. IDFA_console_log

日本語

nendSDK iOS について

SDKの組み込み

広告の表示

全般設定

導入サポート


English

About nendSDK iOS

SDK Implementation

Display Ads

Global Settings

Supports

Clone this wiki locally