nend広告が表示されない間自社広告を表示する

| コメント(0) | トラックバック(0)
こんにちは。開発担当のICTFです。

以前「iAdが表示されない間自社広告を表示する」方法についてご紹介しましたが、今回はnend広告についても自社広告を表示できるようにしてみようと思います。
※nendSDKの使い方について解説はしません。

仕様は前回と同じく、通常のNADViewクラスと同様の使い方ができるものを目指します。
NADView独特の特徴ですが、iAdの時のように広告ビューのサブクラス内で自社広告画像をaddSubViewすると言った方法を取った場合、nand広告が切り替わるタイミングで自社広告がremoveされてしまいます。
一度広告が表示されても電波状況などで受信失敗→自社広告を表示したいというケースが考えられますので、前回の方法は取れません。
解決策としてUIViewをNADViewと自社広告Viewのコンテナとして用意し、その上で両者の表示を切換えようと思います。

以下実装です。
【NADViewEx】
#import "NADView.h"


@interface NADViewEx : UIView

<NADViewDelegate>

{

NADView* _nadView;

UIImageView* _ictfAdView;

}


-(id)initWithFrame:(CGRect)frame rootViewController:(UIViewController*)rootViewController;


@end


【NADViewEx.m】

@interface NADViewEx ()


// 自社広告のタップイベント

-(void) adIctfAdTapHandle:(UITapGestureRecognizer*)sender;


@end


@implementation NADViewEx


- (id)initWithFrame:(CGRect)frame rootViewController:(UIViewController*)rootViewController

{

    self = [super initWithFrame:frame];

    if (self) {

// NADView

_nadView = [[NADView alloc] initWithFrame:frame];

[_nadView setNendID:NAD_KEY spotID:NAD_ID];

[_nadView setBackgroundColor:[UIColor clearColor]];

[_nadView setRootViewController:rootViewController];

[_nadView setDelegate:self];

[_nadView load:nil];

[self addSubview:_nadView];

// 自社広告を追加

_ictfAdView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ICTF_Ad320.png"]] autorelease];

[self addSubview:_ictfAdView];

_ictfAdView.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5);

_ictfAdView.userInteractionEnabled = YES;

// 自社広告のタップイベント

UITapGestureRecognizer* tapGesture =  [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adIctfAdTapHandle:)] autorelease];

tapGesture.numberOfTapsRequired = 1;

[_ictfAdView addGestureRecognizer:tapGesture];

    }

    return self;

}


-(void) dealloc

{

_nadView.delegate = nil;

[_nadView release];

[super dealloc];

}


// Adの初回読み込み完了

-(void) nadViewDidFinishLoad:(NADView *)adView

{

NSLog(@"Ad初回読み込み成功");

}


// Adの読み込み完了通知

-(void) nadViewDidReceiveAd:(NADView *)adView

{

NSLog(@"Ad読み込み成功");

_ictfAdView.hidden = YES;

_nadView.hidden = NO;

}


// Adの読み込み失敗通知

-(void) nadViewDidFailToReceiveAd:(NADView *)adView

{

NSLog(@"Ad読み込み失敗");

_ictfAdView.hidden = NO;

_nadView.hidden = YES;

}


// 自社広告のタップイベント

-(void) adIctfAdTapHandle:(UITapGestureRecognizer*)sender

{

// AppStoreを開く

NSURL* url = [NSURL URLWithString:@"https://itunes.apple.com/jp/app/perfect-listener-voice-player/id570553082?mt=8"];

UIApplication* application = [UIApplication sharedApplication];

if ([application canOpenURL:url]) {

[application openURL:url];

}

}


@end


使い方は普通のNADViewと同じです。

adView = [[[NADViewEx alloc] initWithFrame:CGRectMake(0, 0, NAD_ADVIEW_SIZE_320x50.width, NAD_ADVIEW_SIZE_320x50.height) rootViewController:rootViewController] autorelease];


トラックバック(0)

トラックバックURL: http://www.ict-fractal.com/MovableType/mt/mt-tb.cgi/51

コメントする

Twitterボタン
Twitterブログパーツ