iAd Banner View Delegate Not Calling Methods

2019-07-29 17:22发布

问题:

I have an iAd banner view, with all my contracts up and running, and I've implemented the ADBannerView delegate. The banner should disappear with no internet connection, but it just shows a white box where the content should be. I know I have all the code right, I've seen a million tutorials on this. So I ran some tests and found that the banner view wasn't even calling the two methods for the delegate! Here is the code.

In the .h file:

#import <iAd/iAd.h>

@interface DetailViewController : ADBannerViewDelegate>
{
    ADBannerView *aBanner;
    BOOL bannerIsVisible;
}

@property (nonatomic, retain) IBOutlet ADBannerView *aBanner;
@property (nonatomic, assign) BOOL bannerIsVisible;

@end

in the .m file:

@implementation DetailViewController

@synthesize aBanner,bannerIsVisible;

//Show banner if can load ad.
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
      { 
         if (!self.bannerIsVisible) { 
            [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height); 
            [UIView commitAnimations]; self.bannerIsVisible = YES; }
      }

    //Hide banner if can't load ad.
    -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    { 
        if (self.bannerIsVisible) { 
            [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);           
            [UIView commitAnimations]; self.bannerIsVisible = NO; }
    }

回答1:

You have to set the banner delegate to files owner. I had the same issue and after beating my head against the wall it was that simple.



回答2:

Use the code shown below to declare your own delegate

-(void)viewDidLoad {
  aBanner.delegate = self;
}