iAd - 无法正常工作

时间:2011-11-13 15:17:47

标签: iphone objective-c ios5 iad

我正在我的应用程序中添加iAd ....我设法让横幅从底部滑动(正好在我的标签栏上方,我猜是0,410)...但只有当我启动应用程序时时间。然后我尝试在我的测试设备上关闭wifi以检查我是否得到空白横幅我收到以下消息:ADBannerView:警告横幅视图(0x1b11d0)有广告但可能会被遮挡。此消息仅在每个横幅视图中打印一次。可以请有人帮助我吗?

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{

if (!self.bannerIsVisible) {
    [UIView beginAnimations:@"animatedAdBannerOn" context:NULL];
    NSLog(@"there are ads to show");
    banner.frame = CGRectOffset(banner.frame, 0, -50);
    [UIView commitAnimations];
    self.bannerIsVisible = YES;
}
}
//----hide banner if can't load ad.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{ 

if (!self.bannerIsVisible) {
    [UIView beginAnimations:@"animatedAdBannerOff" context:NULL];
    NSLog(@"sorry, no ads ");
    banner.frame = CGRectOffset(banner.frame, 0, 410);
    [UIView commitAnimations];
    self.bannerIsVisible = NO;
}
}
- (void)viewDidLoad {

[super viewDidLoad]; 



aBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
aBanner.frame = CGRectOffset(aBanner.frame, 0, 410);
aBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
aBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:aBanner];



aBanner.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];

我知道CGRectOffset中有问题,但我无法弄明白。 感谢

1 个答案:

答案 0 :(得分:0)

发现问题....只是一个简单的“!”这里修改了代码:

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{

if (!self.bannerIsVisible) {
    [UIView beginAnimations:@"animatedAdBannerOn" context:NULL];
    NSLog(@"there are ads to show");
    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) { //THE PROBLEM WAS HERE!!!!
    [UIView beginAnimations:@"animatedAdBannerOff" context:NULL];
    NSLog(@"sorry, no ads ");
    banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
    [UIView commitAnimations];
    self.bannerIsVisible = NO;
}
}

 - (void)viewDidLoad {

[super viewDidLoad]; 



aBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
aBanner.frame = CGRectOffset(aBanner.frame, 0, 410);    
aBanner.requiredContentSizeIdentifiers = [NSSet   setWithObject:ADBannerContentSizeIdentifierPortrait];
aBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:aBanner];



aBanner.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];