iAd: "didFailToReceiveAdWithError" not executing

Discussion in 'iPhone/iPad Programming' started by Danneman101, Jul 3, 2010.

  1. macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    Ive read almost everything Ive found on the subject on this forum and elsewhere, but I still cant get "didFailToReceiveAdWithError" to execute, and thus an empty iAd-banner is still displayed even when the wifi is turned off.

    To keep the sample simple Ive included only what is relevant to the iAd-code.

    Ive imported the iAd-framwork to my project, and the code runs the first piece of code (inside "viewWillAppear") successfully. But never will the add disappear (when turning off the wifi), and never will the log even show didFailToReceiveAdWithError.

    MyViewController.h
    Code:
    #import <iAd/ADBannerView.h>
    #import <iAd/iAd.h>
    
    @interface MyViewController : UIViewController <ADBannerViewDelegate>
    {
    	ADBannerView *adView;
    	BOOL bannerIsVisible;
    }
    @property (nonatomic, assign) BOOL bannerIsVisible;
    
    MyViewController.m
    Code:
    #import "MyViewController.h"
    @implementation MyViewController
    
    @synthesize bannerIsVisible;
    
    - (void)viewWillAppear:(BOOL)animated
    {
    	if (!bannerIsVisible){
    		
    		NSLog(@"Show iAd");	
    		
    		adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    		adView.frame = CGRectOffset(adView.frame, 0, 367);
    		adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    		[self.view addSubview:adView];
    		adView.delegate=self;
    		bannerIsVisible = YES;
    	}
    }
    
    - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    {
    	NSLog(@"didFailToReceiveAdWithError");		
    
    	if (bannerIsVisible){
    		[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    		adView.frame = CGRectOffset(adView.frame, 0, +50);
    		[UIView commitAnimations];
    		bannerIsVisible = NO;
    	}
    }
    
    Am I wrong in thinking that the error should execute when the wifi is turned off? Otherwise, what could be the problem?
     
  2. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    You should be starting with it hidden and move it into place when it loads an ad. That method is only called when its already displayed and receives an error.
     
  3. macrumors 65816

    Joined:
    Aug 24, 2005
    #3
    Assuming you're a registered developer go and watch the iAd WWDC video - the 'ideal implementation' is an exact answer to this problem :) Worked for me anyways.
     
  4. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #4
    LastLine: I cant find that video. Been looking in http://developer.apple.com/iphone/appstore/iad/ but nothing.

    jared_kipe: I tried that approach and it did work better. Thanks :)


    Code:
    // Synt:		iAd (v.4.0)
    @synthesize bannerIsVisible;
    
    - (void)viewWillAppear:(BOOL)animated
    {
    	// ----------
    	// iAD
    	// ----------
    	// info:	Initierar iAd (v.4.0)
    	if (!bannerIsVisible)
    	{		
    		NSLog(@"Show iAd");	
    		
    		adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    		adView.frame = CGRectOffset(adView.frame, 0, 417);	// Dont show ad yet	
    		adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
    		adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    		[self.view addSubview:adView];
    		adView.delegate=self;
    	}
    }
    // ----------
    // iAD
    // ----------
    // info:	Hides iAd if error (v.4.0)
    - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    {
    	NSLog(@"Bannerview error");		
    	
    	if (bannerIsVisible){
    		[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    		adView.frame = CGRectOffset(adView.frame, 0, +50);	// Move below screen
    		[UIView commitAnimations];
    		bannerIsVisible = NO;
    	}
    }
    // ----------
    // iAD
    // ----------
    // info:	Shows iAd (v.4.0)
    - (void)bannerViewDidLoadAd:(ADBannerView *)banner
    {
    	NSLog(@"Bannerview did load");		
    	
    	if (!bannerIsVisible)	{
    		[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
    		adView.frame = CGRectOffset(adView.frame, 0, -50);	// Show at bottom of screen
    		[UIView commitAnimations];
    		bannerIsVisible = YES;
    	}	
    }
    // ----------
    // iAD
    // ----------
    // info:	Resumes WebView and hides ProgressView when iAd is shut down (v.4.0)
    - (void)bannerViewActionDidFinish:(ADBannerView *)banner
    {
    	// -------------------
    	// Show:	WebView
    	// -------------------
    	[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.style.visibility='visible';"]];		
    
    	// ---------------------
    	// Stop:	ProgressView
    	// ---------------------
    	[activityView stopAnimating];	
    	[activityView hidesWhenStopped];
    	[self.view sendSubviewToBack:progressAlert];	
    }
    
     

Share This Page