PDA

View Full Version : iAd: "didFailToReceiveAdWithError" not executing




Danneman101
Jul 3, 2010, 10:39 AM
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

#import <iAd/ADBannerView.h>
#import <iAd/iAd.h>

@interface MyViewController : UIViewController <ADBannerViewDelegate>
{
ADBannerView *adView;
BOOL bannerIsVisible;
}
@property (nonatomic, assign) BOOL bannerIsVisible;


MyViewController.m

#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?



jared_kipe
Jul 3, 2010, 11:51 AM
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.

LastLine
Jul 3, 2010, 01:03 PM
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.

Danneman101
Jul 3, 2010, 03:31 PM
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 :)



// 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];
}