@interface NADViewEx : UIView
<NADViewDelegate>
{
NADView* _nadView;
UIImageView* _ictfAdView;
}
-(id)initWithFrame:(CGRect)frame rootViewController:(UIViewController*)rootViewController;
@end
@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
adView = [[[NADViewEx alloc] initWithFrame:CGRectMake(0, 0, NAD_ADVIEW_SIZE_320x50.width, NAD_ADVIEW_SIZE_320x50.height) rootViewController:rootViewController] autorelease];
コメントする