2) iOS

Before proceeding this chapter, be sure that you already finished SDK settings. If not, check 4) iOS Settings first.

[TnkInterstitialAd]

Three steps to show an interstitial ad : 1) allocate an object of TnkInterstitialAd 2) invoke prepare 3) invoke show. Sample below show the simplest way to show a non-incentive interstitial ad on your iOS app.

TnkInterstitialAd

@implementation ViewController {

    TnkInterstitialAd *tnkInterstitial;

}


- (void)viewDidLoad {

    [super viewDidLoad];


    // 1) allocation an object of TnkInterstitialAd

    tnkInterstitial = [[TnkInterstitialAd alloc] init];

    

    // 2) invoke prepare

    [tnkInterstitial prepare];


    // 3) invoke show

    [tnkInterstitial show];

    

}



For incentive interstitial ad, set parameter TNK_PPI when invoking prepare method.

Incentive Ad Sample

@implementation ViewController {

    TnkInterstitialAd *tnkInterstitial;

}


- (void)viewDidLoad {

    [super viewDidLoad];


    // 1) allocation an object of TnkInterstitialAd

    tnkInterstitial = [[TnkInterstitialAd alloc] init];

    

    // 2) invoke prepare ( with TNK_PPI for incentive interstitial ad)

    [tnkInterstitial prepare:TNK_PPI];


    // 3) invoke show

    [tnkInterstitial show];

    

}



[Display Logic]

To control each interstitial Ads in different locations, you have to use 'Display logic'. (See Display Logic) You can put a name of display logic at the end of prepare method. 

Display Logic Sample

@implementation ViewController {

    TnkInterstitialAd *tnkInterstitial;

}


- (void)viewDidLoad {

    [super viewDidLoad];


    // 1) allocate an object of TnkInterstitialAd

    tnkInterstitial = [[TnkInterstitialAd alloc] init];

    

    // 2) invoke prepare (with the name of display logic)

    [tnkInterstitial prepare:@"cross_first"];


    // 3) invoke show

    [tnkInterstitial show];

    

}



[Using Delegate]

To catch events when an interstitial ad is loaded or users close interstitial ads, use TnkInterstitialDelegate protocol.

TnkInterstitialDelegate protocol

#define AD_CLOSE_SIMPLE     0   // User closed ad view by clicking close button.

#define AD_CLOSE_CLICK      1   // User clicked ad view and it is closed.


#define AD_FAIL_NO_AD       -1  // no ad available

#define AD_FAIL_NO_IMAGE    -2  // ad image not available

#define AD_FAIL_TIMEOUT     -3  // ad arrived after 5 secs.

#define AD_FAIL_CANCEL      -4  // ad frequency settings

#define AD_FAIL_NOT_PREPARED     -5      // not prepared


#define AD_FAIL_SYSTEM      -9


#define TNK_PPI             @"__tnk_ppi__"

#define TNK_CPC             @"__tnk_cpc__"


@protocol TnkInterstitialDelegate <NSObject>


@optional


// Called when interstitial view is closed. Reason type is passed in the second parameter.

- (void)didInterstitialClose:(TnkInterstitialAd *)ad close:(int)type;


// Called when failed to display ad.

// Error code is passed in the second parameter

- (void)didInterstitialFail:(TnkInterstitialAd *)ad error:(int)errCode;


// Called when interstitial ad is displayed

- (void)didInterstitialShow:(TnkInterstitialAd *)ad;


// Called when an interstitial ad is loaded from server.

// If show method is called before ad is loaded, 

// then didInterstitialShow is called instead of didInterstitialLoad when an interstitial ad is loaded.

- (void)didInterstitialLoad:(TnkInterstitialAd *)ad;


@end


You can set TnkInterstitialDelegate object by passing it the second parameter of prepare method or by directly assigning to TnkInterstitialAd object.
Following sample code shows how developers can control displaying interstitial ads using TnkInterstitialDelegate

TnkInterstitialDelegate Sample

#import "tnksdk.h"


@interface ViewController : UIViewController <TnkInterstitialDelegate> {

    // ...

}

@end


@implementation ViewController {

    TnkInterstitialAd *tnkInterstitial;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    

    // 1) allocate an object of TnkInterstitialAd

    tnkInterstitial = [[TnkInterstitialAd alloc] init];

    

    // 2) invoek prepare (with a name of display logic and delegate)

    [tnkInterstitial prepare:@"cross_first" delegate:self];


}


#pragma mark - TnkInterstitialDelegate


- (void) didInterstitialLoad:(TnkInterstitialAd *)ad {

    NSLog(@"Interstitial Loaded : %@", ad.logicName);

    

    if (okToShow) {

        [ad show];

    }

}

 
[TnkInterstitialAd Interface]

TnkInterstitialAd Interface

@interface TnkInterstitialAd : NSObject <TnkServiceCallback>


@property (nonatomic, weak) UIViewController *viewControllerToShow;

@property (nonatomic, weak) id<TnkInterstitialDelegate> delegate;

@property (nonatomic, strong) NSString *logicName;

@property (nonatomic, assign) NSTimeInterval timeoutSec;


- (void) prepare;

- (void) prepare:(NSString *)logicName;

- (void) prepare:(NSString *)logicName delegate:(id<TnkInterstitialDelegate>) delegate;


- (void) show:(UIViewController *)viewController;

- (void) show;


@end


- properties

 Property 내용
 logicNameEnter TNK_PPI for incentive ads and TNK_CPC for non-incentive ads.
Or enter any other string for Display Logic See 5) Display Logic for details.
 delegate TnkInterstitialDelegate object.
 viewControllerToShow a ViewController on which an interstitial ad displayed. if not assigned, rootViewController of current UIWindow is used.
 timeoutSec timeout in sec (default 5 sec). If any ad is not loaded after timeout sec.show, didInterstitialFail:error: is invoked with errorCode of -3 (AD_FAIL_TIMEOUT)

- prepare

Method
  - (void) prepare
  - (void) prepare:(NSString *)logicName
  - (void) prepare:(NSString *)logicName delegate:(id<TnkInterstitialDelegate>)delegate

Description
Load an interstitial ad from server. 
  • didInterstitialLoad: is invoked when an ad-loading is completed.
  • didInterstitialFail:error is invoked if ad has failed to load.
  • successive invocations to prepare method are ignored. 

- show

Method
  - (void) show
  - (void) show:(UIViewController *)viewController

Description
Display an interstitial ad loaded by prepare invocation. 
  • didInterstitialShow: is invoked just after an ad is displayed.
  • didInterstitialClose:type: is invoked when the interstitial ad is closed. When a user clicks a close button then 0 (AD_CLOSE_SIMPLE) is passed to type parameter. When a user clicks ad image then 1 (AD_CLOSE_CLICK) is passed to type parameter.
  • if you invoke show method without previously invoking prepare method, then didInterstitialFail:error: is invoked with type parameter of -5 (AD_FAIL_NOT_PREPARED). 
  • if an interval has not passed when you invoke show method, then didInterstitialFail:error: is invoked with type parameter of -4 (AD_FAIL_CANCEL). You can control the intervals between successive shows by Display logic configuration.
Subpages (1): Old APIs
Comments