共享的iAd横幅bannerViewDidLoadAd未被调用
我正在使用以下代码来设置共享的iAd横幅广告。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _adView = [[ADBannerView alloc]init]; }
ViewController.m
-(void) viewWillAppear:(BOOL)animated { AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate]; _adView = [appdelegate adView]; _adView.delegate = self; self.canDisplayBannerAds = true; } - (void)bannerViewDidLoadAd:(ADBannerView *)banner { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [banner setAlpha:1]; [UIView commitAnimations]; } - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [banner setAlpha:0]; [UIView commitAnimations]; }
bannerView:didFailToReceiveAdWithError
正在按预期调用,但是bannerViewDidLoadAd
永远不会被调用。 我试图在iAd标题加载时在屏幕上移动一些button。
您的共享横幅似乎不只是一个ADBannerView
。 看起来你已经在你的AppDelegate.h
和你的ViewController.h
为你的ADBannerView
设置了多个ADBannerView
。 此外, self.canDisplayBannerAds = true
正在为您创build一个全新的,不同的 ADBannerView
。 self.canDisplayBannerAds = true
可以用于在您的应用程序中实现self.canDisplayBannerAds = true
方式。 这将为您创build一个ADBannerView
,并根据是否从iAdnetworking收到广告来显示或隐藏ADBannerView
。 如果您打算自己实现ADBannerView
则需要从viewDidLoad
删除此项。
以下是您的共享ADBannerView
应该如下所示:
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]; }