how to implement AdBannerview and ADBannerview delegate

jason picture jason · Feb 27, 2011 · Viewed 18.3k times · Source

I am having trouble implementing ADBannerView and its delegate protocol.

I implemented the following code in my view class (also made the view conform to the ADBannerViewDelegate protocol):

//add iAds
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0, 318, 320, 50)];
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.delegate = self; 
//adView.delegate = ADBannerViewDelegate;
[self.view addSubview: adView];

then I created a class for the ADBannerViewDelegate, with the following .m

//
//  ADBannerViewDelegate.m
//

#import "ADBannerViewDelegate.h"

@implementation ADBannerViewDelegate

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"bannerview did not receive any banner due to %@", error);}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(@"bannerview was selected");}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(@"banner was loaded");}

@end

the banners are eventually presented but the console keep throwing the following type of errors:

2011-02-27 15:00:54.108 app[31639:207] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x6356a40 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content}

and the delegate functions are not doing anything , so no NSLog at all. Obviously not catching the errors.

I am stumped. I guess I am missing something in the linkage of the Adbanner view calls in the view and the delegate. Not sure how to do it or what is wrong.

Any help? Thanks in advance.

Jason

Answer

Ajay picture Ajay · Feb 27, 2011

The reason why is you told the AdBannerView that you are its delegate but you never put it in your implementation file. Your implementation file should look like this (notice the line with @implmentation):

//
//  ADBannerViewDelegate.m
//

#import "ADBannerViewDelegate.h"

@implementation ADBannerViewDelegate<ADBannerViewDelegate>

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"bannerview did not receive any banner due to %@", error);}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(@"bannerview was selected");}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(@"banner was loaded");}

@end

And also you shouldn't name your class ADBannerViewDelegate. Your class should be a delegate (respond to it) to ADBannerView but not be named after it.