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

Implementation for interstitial ads

fan-w-suzuki edited this page Jul 8, 2020 · 11 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 For Interstitial Ads

Loading the ad

First, send loadAdWithSpotID:apiKey: to NADInterstital and load the ad.
※We recommend implementing the load processing after the app runs.
Ex. UIApplicationDelegate Protocol is implemented application:didFinishLaunchingWithOptions: etc.

Swift
import UIKit
import NendAd

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        // NADInterstitial Implement with a single pattern
        // sharedInstance You can retrieve the Instance via Message like below
        NADInterstitial.sharedInstance().loadAd(withSpotID: spotID, apiKey: "apiKey")

        return true
    }

}
Objective-C
#import <NendAd/NADInterstitial.h> // Import the Header File

@implementation YourAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    [[NADInterstitial sharedInstance] loadAdWithSpotID:spotID apiKey:@"apiKey"];
    return YES;
}

@end

Through the use of NADInterstitial[XXX]Delegate (e.g Loading, Click), you can listen for these events are fired. For more information, please refer to Property, NADInterstitialLoadingDelegate and NADInterstitialClickDelegate of the Information on NADInterstital Content.

Displaying Ads

By sending showAdFromViewController:, you can display ads. Set UIViewController in the ad you want to display to the parameter and send a message.
Please note that if the ad is not completely read, then the interstitial ad will not be displayed.

The ad will not display if you click on the X button on the top right or anywhere outside the ad. If you tap in the banner ad or install ad, it will take you to the App Store.

image

Regarding the content of the return value of NADInterstitialShowResult, please refer to the sample code below.

Swift
import UIKit
import NendAd

class YourOriginalClass: UIViewController {

    func showButtonClicked(_ sender: UIButton) {
        let showResult = NADInterstitial.sharedInstance().showAd(from: self)

        switch (showResult) {
        case .AD_SHOW_SUCCESS:
            print("Ad is displayed successfully")
            break
        case .AD_SHOW_ALREADY:
            print("Ad has already displayed successfully")
            break
        case .AD_FREQUENCY_NOT_REACHABLE:
            print("The frequency cap has not been reached ")
            break
        case .AD_LOAD_INCOMPLETE:
            print("Ad has not been loaded or in the process of loading ")
            break
        case .AD_REQUEST_INCOMPLETE:
            print("Ad request has failed")
            break
        case .AD_DOWNLOAD_INCOMPLETE:
            print("Ad has not finished downloading ")
            break
        case .AD_CANNOT_DISPLAY:
            print("Ad cannot be displayed in the designated ViewController ")
            break
        @unknown default:
            break
        }
    }

}
Objective-C
#import <NendAd/NADInterstitial.h> // Import the header file

@implementation YourOriginalClass : UIViewController

- (void)showInterstitialAdSample
{
    NADInterstitialShowResult result = [[NADInterstitial sharedInstance] showAdFromViewController:self];
    switch (result) {
        case AD_SHOW_SUCCESS:
            NSLog(@"Ad is displyed successfully");
            break;
        case AD_SHOW_ALREADY:
            NSLog(@"Ad has already displayed successfully");
            break;
        case AD_FREQUENCY_NOT_REACHABLE:
            NSLog(@"The frequency cap has not been reached");
            break;
        case AD_LOAD_INCOMPLETE:
            NSLog(@"Ad has not been loaded or in the process of loading");
            break;
        case AD_REQUEST_INCOMPLETE:
            NSLog(@"Ad request has failed");
            break;
        case AD_DOWNLOAD_INCOMPLETE:
            NSLog(@"Ad has not finished downloading");
            break;
        case AD_CANNOT_DISPLAY:
            NSLog(@"Ad cannot be displayed in the designated ViewController");
            break;
    }
}

@end

Dismiss Ads

You can stop displaying ads by sending dismissAd to the NADInterstitial Class.

Swift
import UIKit
import NendAd

class YourOriginalClass: UIViewController {

    func dismissInterstitialAdSample(){
        NADInterstitial.sharedInstance().dismissAd()
    }

}
Objective-C
#import <NendAd/NADInterstitial.h> // import the header file

@implementation YourOriginalClass : UIViewController

- (void)dismissInterstitialAdSample
{
    [[NADInterstitial sharedInstance] dismissAd];
}

@end

Verification

日本語

nendSDK iOS について

SDKの組み込み

広告の表示

全般設定

導入サポート


English

About nendSDK iOS

SDK Implementation

Display Ads

Global Settings

Supports

Clone this wiki locally