我想在我的应用中加入iAds。当有网络连接时它工作正常但是当网络不可用时iAds不会隐藏..请找到下面的代码并帮助我......感谢你的时间..
我在viewDidLoad
中包含了这段代码static NSString * const kADBannerViewClass = @"ADBannerView";
if (NSClassFromString(kADBannerViewClass) != nil) {
if (self.adView == nil) {
self.adView = [[[ADBannerView alloc] init] autorelease];
self.adView.delegate = self;
self.adView.frame = CGRectMake(0,355,320,60);
self.adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
}
}
[self.view addSubview:self.adView];
委托方法:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {
[UIView beginAnimations:nil context:NULL];
banner.frame = CGRectOffset(banner.frame, 0,10);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible) {
[UIView beginAnimations:nil context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -10);
[UIView commitAnimations];
self.bannerIsVisible = NO;
NSLog(@"%@",error);
}
}
答案 0 :(得分:9)
如果我正确理解您的代码,您最初会显示横幅广告。这是不正确的。最好先将屏幕移出屏幕,然后仅在收到bannerViewDidLoadAd:
时将其移至屏幕上,并在收到bannerView:didFailToReceiveAdWithError:
后退出屏幕。
这也有一个优点,即您的横幅视图最初不会显示为空。如果网络连接速度很慢,可能会发生这种情况。
答案 1 :(得分:0)
You can do like this
Hide banner during viewdidload and write this in .m file.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(@"Error loading iAd");
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(@"Ad loaded");
self.banner.hidden = NO;
}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner{
NSLog(@"Ad will load");
self.banner.hidden = NO;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
NSLog(@"Ad did finish");
self.banner.hidden = NO;
}