Shared iAd banner bannerViewDidLoadAd not being called

空扰寡人 提交于 2019-11-28 13:08:05

Your shared banner does not appear to be just one ADBannerView. It looks like you've set multiple @property's for your ADBannerView in your AppDelegate.h and your ViewController.h. Also, self.canDisplayBannerAds = true is creating an entirely new and different ADBannerView for you. self.canDisplayBannerAds = true can be used for a no hassle way of implementing iAds in your application. This will create a ADBannerView for you and show or hide the ADBannerView depending on whether it receives an ad or not from the iAd network. You will want to remove this from your viewDidLoad if you plan to implement a ADBannerView yourself.

Here is what your implementation of your shared ADBannerView should look like:

AppDelegate.h

#import <UIKit/UIKit.h>
@import iAd;

@interface AppDelegate : UIResponder <UIApplicationDelegate> {

}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ADBannerView *iAdView;

@end

AppDelegate.m

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _iAdView = [[ADBannerView alloc]init];
    return YES;
}

ViewController.h

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

@interface ViewController : UIViewController <ADBannerViewDelegate>

@end

ViewController.m

#import "ViewController.h"

@interface ViewController  ()

@end

@implementation ViewController  {
    AppDelegate *appDelegate;
}

-(void)viewDidLoad {
    [super viewDidLoad];

    appDelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
    appDelegate.iAdView.delegate = self;
    appDelegate.iAdView.frame = CGRectMake(0, 0, appDelegate.iAdView.frame.size.width, appDelegate.iAdView.frame.size.height);
    [self.view addSubview:appDelegate.iAdView];

    // You created another adView property in your ViewController.h?
    //_adView = [appdelegate adView];
    //_adView.delegate = self;

    // This will actually create ANOTHER ADBannerView
    // Do not use when creating your own ADBannerView
    //self.canDisplayBannerAds = true;
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"iAd LOADED");
    [UIView beginAnimations:nil context:NULL];
    appDelegate.iAdView.alpha = 1.0;
    [UIView commitAnimations];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"iAd FAILED");
    [UIView beginAnimations:nil context:NULL];
    appDelegate.iAdView.alpha = 0.0;
    [UIView commitAnimations];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!