AbhinavVinay
AbhinavVinay

Reputation: 303

How do I get the iAD methods to get called

I am trying to display iADs into my cocos2d game scene. I am able to successfully display ads, but I want to be able to show the view controller on screen only when the ad is being displayed.

So for this I tried to use the -(void) bannerViewDidLoadAd:(ADBannerView *)banner method which I believed would get called if I added it in my view controllers implementation. But it doesn't get called at all. Below is my code.

Can you kindly let me know if I am doing anything wrong. Thanks :)

BannerAd.h

@interface BannerAd:  UIViewController <ADBannerViewDelegate>
{
    id delegate;
}

@property (nonatomic, retain) ADBannerView *adView;

-(id)init: (id) dele;
-(void) removeAd;
-(void) bannerViewDidLoadAd:(ADBannerView *)banner;

@end

BannerAd.m

@implementation BannerAd

@synthesize adView = adView_;

-(id)init: (id) dele
{
    if((self=[super init]))
    {
        NSLog(@"init called, delegate set");
        delegate = dele;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    [self.view addSubview:self.adView];
}

-(void) bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"AD did load");
}

Inside my game scene(cocos2d scene) i call this:

    BannerAd *bannerAdDetailView = [[BannerAd alloc] init];
    [bannerAdDetailView init:self];
    [[[CCDirector sharedDirector]view] addSubview:bannerAdDetailView.view];
    [bannerAdDetailView.view setFrame:CGRectMake(0, 0, 320, 568)];

Kindly let me know how i can make sure my app is notified when the ad gets loaded.

Thanks!!

Upvotes: 3

Views: 851

Answers (2)

Anselm Scholz
Anselm Scholz

Reputation: 478

you can use the Ad Banner View Delegate Protocol: – bannerViewDidLoadAd: in this method you could set the banner view visible. Here is the reference if no ad was loaded: Hide Bannerview when no ad was received.

Upvotes: 0

giorashc
giorashc

Reputation: 13713

You need to set the ADBannerView delegate (add to viewDidLoad method):

self.adView.delegate = self;

This tells the banner view who is the target of the method call bannerViewDidLoadAd. In this case its your view controller.

Upvotes: 4

Related Questions