未调用共享的iAd横幅bannerViewDidLoadAd [英] Shared iAd banner bannerViewDidLoadAd not being called
问题描述
我使用以下代码设置共享iAd横幅。
I am using the following code to setup a shared iAd banner.
AppDelegate.m
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_adView = [[ADBannerView alloc]init];
}
ViewController.m
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横幅加载时,我试图在屏幕上移动一些按钮。
bannerView:didFailToReceiveAdWithError
is getting called as expected but bannerViewDidLoadAd
is never called. I am trying to move some buttons up on the screen when the iAd banner loads.
推荐答案
您的共享横幅似乎不是只需一个 ADBannerView
。您似乎已在 AppDelegate中为
和您的 ADBannerView
设置了多个 @property
.h ViewController.h
。此外, self.canDisplayBannerAds = true
为您创建一个完全新的和不同的 ADBannerView
。 self.canDisplayBannerAds = true
可用于在应用程序中实现iAd的 no hassle 方式。这将为您创建一个 ADBannerView
,并显示或隐藏 ADBannerView
,具体取决于它是否从广告收到广告iAd网络。如果您打算自己实现 ADBannerView
,则需要从 viewDidLoad
中删除它。
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.
以下是您的共享 ADBannerView
的实现方式:
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];
}
这篇关于未调用共享的iAd横幅bannerViewDidLoadAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!