This is my first iAd for iPhone.
In development mode, if I switch my iPhone to airport mode, my app being debugged never ever gets this event.
But, if I start app with airport off, I get the 'bannerViewDidLoadAd' event okay. And if airport turned on -- never get didFailToReceiveAdWithError.
@interface ViewController : UIViewController <ADBanne开发者_开发问答rViewDelegate> {
ADBannerView* adView;
}
@property(nonatomic, retain) IBOutlet ADBannerView *adView;
...
- (void)viewDidLoad
{
... (adView is from Interface Builder )
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[self.view addSubview:adView];
adView.delegate=self;
[super viewDidLoad];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"bannerViewDidLoadAd");
if ( adView.hidden )
{
NSLog(@"going visible");
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
adView.hidden = NO;
// banner is invisible now and moved out of the screen on 50 px
//banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"didFailToReceiveAdWithError");
if( !adView.hidden ) // ad banner displayed, but lost ad network
{
NSLog(@"going hidden");
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
adView.hidden = YES;
// banner is visible and we move it out of the screen, due to connection issue
//banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
}
}
The only time
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
is called is when an ad is already displayed and receives an error. When you are in airplane mode the initial ad is never displayed therefore this method is not called.
*Edit for clarity
If you check the Apple Developer Documentation you notice you have 2 options:
- To assist you in validating your implementation, the iAd Network occasionally returns errors to test your error handling code.
- You can also test your error handling support manually by turning your device’s wireless capability off.
http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/iAd_Guide/TestingiAdApplications/TestingiAdApplications.html#//apple_ref/doc/uid/TP40009881-CH6-SW1
Take into account that you can't turn off wireless for the iOS simulator. You need to disable the network connection of your development system:
IPhone Connectivity Testing: How do I force it to lose connection?
精彩评论