Implementation for banner ads - fan-ADN/nendSDK-iOS GitHub Wiki

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.

Step-by-step Implementation for banner ads

This section will explain how to implement NADView, using the simplest structure as an example.
Please refer to the sample sources for other implementation details.

Please refer to here for the implementation of Interface Builder

delegate conformity

Import NADView with the class of a header file which holds the advertising view and conform to NADVieDelegate.

Swift
import UIKit
import NendAd

class YourAppViewController: UIViewController, NADViewDelegate {

    private var nadView: NADView!

}
Objective-C
#import <UIKit/UIKit.h>
#import <NendAd/NADView.h>

@interface YourAppViewController : UIViewController <NADViewDelegate>

@property (nonatomic, strong) NADView *nadView;

@end

Note: For implementation of applications with multiple screens generating an instance for each view controller, please apply Manage the periodic load to each screen, which will be explained later.

e.g. NADView Generation to loading

Swift
import UIKit
import NendAd

class YourAppViewController: UIViewController, NADViewDelegate {

    private var nadView: NADView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Create NADView
        nadView = NADView(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
        // Setting of spotID, apiKey
        nadView.setNendID(3172, apiKey: "a6eca9dd074372c898dd1df549301f277c53f2b9")
        // Setting of Delegate Object
        nadView.delegate = self
        // Loading Ads
        nadView.load()

        self.view.addSubview(nadView)
    }

}
Objective-C
@implementation YourAppViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Create NADView
    self.nadView = [[NADView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    // Setting of spotID, apiKey
    [self.nadView setNendID:3172 apiKey:@"a6eca9dd074372c898dd1df549301f277c53f2b9"];
    // Setting of Delegate Object
    [self.nadView setDelegate:self];
    // Loading Ads
    [self.nadView load];

    [self.view addSubview:self.nadView];
}

@end

NADView Generation

Place an instance as you will, for 320x50 size use CGRect argument.

Swift
nadView = NADView(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
Objective-C
self.nadView = [[NADView alloc] initWithFrame: CGRectMake(0, 0, 320, 50)];

Setting of spotID, apiKey

Set the spotID and apiKey which were published from the management screen of nend to the application's ad space.

Swift
nadView.setNendID(3172, apiKey: "a6eca9dd074372c898dd1df549301f277c53f2b9")
Objective-C
[self.nadView setNendID:3172 apiKey:@"a6eca9dd074372c898dd1df549301f277c53f2b9"];

From this point, you can now access the ad settings information.
If the status of the ad space says “pending”, there will be an input error when you load an ad. Please make sure the status of the application is “active” in the management screen of nend.
You will receive a notification email once the application of the ad space is approved and the status changes automatically. You will be able to publish ads after a few hours after you received the email.
Please use the test ID for implementation testing.

Setting of Delegate Object

When NADView starts receiving ads, it will call the assigned delegate, nadViewDidFinishLoad method for notification. The assigned delegate should be the class which conforms the NADViewDelegate protocol and implements the nadViewDidFinishLoad method.

Swift
nadView.delegate = self
Objective-C
[self.nadView setDelegate:self];

Loading Ads

Use the NADView's load method to start loading ads.

Swift
nadView.load()
Objective-C
[self.nadView load];

If you want to set retry intervals as the non-standard value, please use the method below to start loading.

Swift
// ex) when there is an inquiry error, it inquires again with an interval of 60 minutes.
nadView.load(["retry" : "3600"])
Objective-C
// ex) when there is an inquiry error, it inquires again with an interval of 60 minutes.
[self.nadView load:@{@"retry": @"3600"}];

Delegate notification

Once loading of the ad is done, a notification will be sent using nadViewDidFinishLoad [the delegate which was set at Setting of Delegate Object]. If there is a need to show the NADView after loading is done, it can be done here.

Swift
func nadViewDidFinishLoad(_ adView: NADView!) {
    print("delegate nadViewDidFinishLoad:")
}
Objective-C
- (void)nadViewDidFinishLoad:(NADView *)adView
{
    NSLog(@"delegate nadViewDidFinishLoad:");
}

【optional】ad banner click notification

You can receive a notification when an ad banner gets clicked.
However, even if you count this event, please note that there can be a discrepancy in “actual numbers of ad displayed (the amount of clicks counted by the server)” depending on the network status or environment.

Swift
func nadViewDidClickAd(_ adView: NADView!) {
    print("delegate nadViewDidClickAd")
}
Objective-C
- (void)nadViewDidClickAd:(NADView *)adView
{
    NSLog(@"delegate nadViewDidClickAd:");
}

【optional】Information button click notification

You can receive a notification when an information button gets clicked.

Swift
func nadViewDidClickInformation(_ adView: NADView!) {
    print("delegate nadViewDidClickInformation")
}
Objective-C
- (void)nadViewDidClickInformation:(NADView *)adView
{
    NSLog(@"delegate nadViewDidClickInformation:");
}

【optional】ad reception notification

You can receive a notification when an ad is received successfully.
You can use this when you want to manage ads for every notification.

Swift
func nadViewDidReceiveAd(_ adView: NADView!) {
    print("delegate nadViewDidReceiveAd")
}
Objective-C
- (void)nadViewDidReceiveAd:(NADView *)adView
{
    NSLog(@"delegate nadViewDidReceiveAd:");
}

【optional】ad reception error notification

You can receive a notification when there is a failure in receiving an ad.
It will notify you when there is a problem displaying an ad, such as a communication error or running out of ad placements. At the time of the error, you can use this when you don't want ads to be displayed.

Swift
func nadViewDidFail(toReceiveAd adView: NADView!) {
    // separate by error
    let error = adView.error as NSError

    switch (error.code) {
    case NADViewErrorCode.NADVIEW_AD_SIZE_TOO_LARGE.rawValue:
        // The ad size is larger than the banner size
        break
    case NADViewErrorCode.NADVIEW_INVALID_RESPONSE_TYPE.rawValue:
        // Invalid banner type
        break
    case NADViewErrorCode.NADVIEW_FAILED_AD_REQUEST.rawValue:
        // Failed ad request
        break
    case NADViewErrorCode.NADVIEW_FAILED_AD_DOWNLOAD.rawValue:
        // Failed ad download
        break
    case NADViewErrorCode.NADVIEW_AD_SIZE_DIFFERENCES.rawValue:
        // difference in ad sizes
        break
    default:
        break
    }
}
Objective-C
- (void)nadViewDidFailToReceiveAd:(NADView *)adView
{
    NSLog(@"delegate nadViewDidFailToLoad:");
    // separate by error
    NSError* error = adView.error;
    NSString* domain = error.domain;
    int errorCode = error.code;
    // You can still access it through the application side by using the domain.
    NSLog(@"%@",[NSString stringWithFormat: @"code=%d, message=%@", errorCode, domain]);
    switch (errorCode) {
        case NADVIEW_AD_SIZE_TOO_LARGE:
            // The ad size is larger than the banner size
            break;
        case NADVIEW_INVALID_RESPONSE_TYPE:
            // Invalid banner type
            break;
        case NADVIEW_FAILED_AD_REQUEST:
            // Failed ad request
            break;
        case NADVIEW_FAILED_AD_DOWNLOAD:
            // Failed ad download
            break;
        case NADVIEW_AD_SIZE_DIFFERENCES:
            // difference in ad sizes
            break;
        default:
            break;
    }
}

Details of NADViewErrorCode (NADView.NSError.code)

NADViewErrorCode Error Information
NADVIEW_FAILED_AD_REQUEST Failed to receive ad (network error, server error, out of ads, etc.)
NADVIEW_AD_SIZE_TOO_LARGE The ad size is larger than the banner size
NADVIEW_AD_SIZE_DIFFERENCES Difference in ad sizes ※
NADVIEW_INVALID_RESPONSE_TYPE Invalid banner type ※
NADVIEW_FAILED_AD_DOWNLOAD Failed to receive ad

※ It is unlikely to happen

Managing periodical loading

If you began loading ads and nothing appears, please try the following below:

This applies to:

  • In applications that transition across multiple screens.
  • If you create an ad instance separately on each screen.
  • Managing and switching multiple ads (ad switching SDK is included).

Discontinue periodical loading

When an ad or View screen transitions do not display, you can discontinue periodical ad loading by sending a pause message.

Ex: When the screen disappears, discontinue periodical loading

Swift
override func viewWillDisappear(_ animated: Bool) {
    nadView.pause()
}
Objective-C
- (void)viewWillDisappear:(BOOL)animated
{
    [self.nadView pause];
}

Restart periodical loading

When an ad reappears on the screen or the View in screen transitions displays, you can restart periodical ad loading by sending a resume message.

Ex: When the screen appears, restart periodical loading

Swift
override func viewWillAppear(_ animated: Bool) {
    nadView.resume()
}
Objective-C
- (void)viewWillAppear:(BOOL)animated
{
    [self.nadView resume];
}

Verification

⚠️ **GitHub.com Fallback** ⚠️