views:

105

answers:

1

Hey All, I am trying to include iAds in my app. It works fine when there is network connection but the iAds doesn't hide when the network is not available..please find the code below and help me..thanks for your time..

I included this code in 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];

Delegate methods:

- (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);
 }
}
+5  A: 

If I understand your code correctly, you are initially showing the banner. That is not correct. It is better to initially move the banner off-screen and then only move it on-screen when you receive bannerViewDidLoadAd: and back off-screen when you receive bannerView:didFailToReceiveAdWithError:.

This also has the advantage that your banner view does not initially show up empty. Which can happen if there is a slow network connection.

St3fan
thanks for the reply..so in the viewDidLoad should I set bannerIsVisible to NO ??
racharambola
I tried but I think I did a mistake..I am experiencing exactly what you said..initially for some time it shows up empty and later loads the view..if you please don't mind can you please suggest me where to make changes in the code I wrote
racharambola
No in `viewDidLoad` you place the add offscreen. So that would be at position `(0,460)` if you just have a status bar. Then when the ad is loaded you animate the whole Ad view up 50 pixels. And shrink your content also by 50 pixels. Check the WWDC iAds session videos and slides (free), it describes this technique in detail.
St3fan
that worked..thanks a lot!!
racharambola