Reputation: 2052
I have implimented the iAd code, however both on the simulator and on my device it likes to make the iAd disappear after a while, even when the internet connection is fine. Is there something that I did wrong with my implementation, or is this just expected? Below is both the code, and the Console that shows how often both are being called. Thanks!
- (void)viewDidLoad {
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 435); //orginally -50
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
[super viewDidLoad];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"bannerViewDidLoadAd");
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, -25); //orginally 50
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"bannerViewRecievedError");
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, 25); //orginally -50
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)dealloc {
NSLog(@"dealloc");
adView.delegate=nil;
[adView release];
[super dealloc];
}
Heres what the console says:
2010-12-29 20:04:17.717 app[48943:207] bannerViewRecievedError
2010-12-29 20:04:52.410 app[48943:207] bannerViewRecievedError
2010-12-29 20:05:17.168 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:05:47.166 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:06:16.993 app[48943:207] bannerViewRecievedError
2010-12-29 20:06:46.803 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:07:17.314 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:07:47.140 app[48943:207] bannerViewRecievedError
2010-12-29 20:08:19.899 app[48943:207] bannerViewRecievedError
2010-12-29 20:08:46.978 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:09:17.106 app[48943:207] bannerViewRecievedError
2010-12-29 20:09:46.930 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:10:17.114 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:10:47.609 app[48943:207] bannerViewDidLoadAd
Upvotes: 1
Views: 649
Reputation: 78343
It's designed to do this to ensure that you can deal with iAd errors correctly. It will randomly give you errors as well as good test data.
Upvotes: 0
Reputation: 11038
Nope, there's no problem here. Apple serves up new simulated ads every so often, and sometimes you'll get hit with an error to test your error-handling capabilities. The error probably means "No Inventory Available", which would make your ad disappear. From the relevant developer documentation:
If an error occurs, the banner view calls the delegate’s bannerView:didFailToReceiveAdWithError: method. When this happens, your application must hide the banner view. Listing 2-3 shows one way you might implement this. It uses the same property as Listing 2-2 to keep track of whether the banner is visible. If the banner is visible and an error occurs, it moves the banner off the screen.
Even after an error is sent to your delegate, the banner view continues to try to download new advertisements. The combination of these two delegate methods allows you to display the banner only when advertisements are loaded.
Nice job on a good error handling implementation!
Upvotes: 1