Reputation: 4882
I am building an app in which I want to us iAd banners. the viewcontroller in which I want to show the ad is a UIViewController. I am using storyboards. I implemented the iAd banner exactly as apple shows/demonstrates here:
"<iAd/iAd.h>"
headerself.canDisplayBannerAds = YES;
but when I run my app, no iAd is showing up. do I forget something? Thank you so much in advance
Upvotes: 2
Views: 1595
Reputation: 489
I had a bit different issue, but the answer fits to your question as well. I updated my old xib file (was from XCode 5.1) to use Size Classes
in XCode 6.0. After the update ads showed only in iPhone 4 - 5 and 5s. iPhone 6 and iPhone 6 Plus was without banners (simulators showed the same results as the external devices). When using xib file and using
self.canDisplayBannerAds = YES;
in my situation I moved this command from viewDidLoad
to viewDidAppear
and banner showed up. Now I can see banners in all devices.
Upvotes: 1
Reputation: 4882
The problem was that I had to sign the iAd contract in itunes connect, which I had not done yet. it works fine now!
Upvotes: 0
Reputation: 8247
In your .h :
@interface MyViewController : UIViewController <ADBannerViewDelegate>
Add a banner view in your xib file and link this banner view with an IBOutlet
@property (nonatomic, strong) IBOutlet ADBannerView *iAdBannerView;
add the following code to display your ad :
#pragma mark - ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"banner loaded");
// Display BannerView
_iAdBannerView.hidden = NO;
[UIView animateWithDuration:0.4f
animations:^{
_iAdBannerView.alpha = 1.0f;
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
// Print error
NSLog(@"error banner failed :\n%@", error);
// Hide BannerView
[UIView animateWithDuration:0.4f
animations:^{
_iAdBannerView.alpha = 0.0f;
} completion:^(BOOL finished) {
_iAdBannerView.hidden = YES;
}];
}
and normally your adbanner will appear when you receive and ad and disappear otherwise.
Upvotes: 0