Reborn
Reborn

Reputation: 145

Display Ads with iAd without Storyboard or Xib

I have been trying to make a banner ad appear at the bottom of my App, without the use of storyboards or Xib files. Sadly this is not working out. I have tried following tutorials, and just not adding the Storyboard, to no avail. My project compiles fine but the Ad is not displayed at the bottom of the simulator, or anywhere for that matter. Here is a relevant sample of my viewcontroller.mm code:

@implementation ViewController
{
    ADBannerView *_bannerView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:(_bannerView)];
    self.canDisplayBannerAds = true;

}

The header imports , iAd.framework is included. The header also has this modified line @interface ViewController : UIViewController <ADBannerViewDelegate>

Upvotes: 1

Views: 130

Answers (2)

Karlo A. L&#243;pez
Karlo A. L&#243;pez

Reputation: 2668

You are not initializing bannerView, if you dont initialize it, like any other UI object you will not see anything. So initialize it first, then you add it to the view and also enable canDisplayBannerAds to prevent any errors.

@implementation ViewController{
ADBannerView *_bannerView; }

- (void)viewDidLoad{
[super viewDidLoad];
 self.canDisplayBannerAds = true;
 //_bannerView = [[ADBannerView alloc]initWithFrame:CGRectMake(0,0,320,50)];

//Instead of giving the position when initializing, give the AdType
        bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];

//Then give the position
        [view setFrame:CGRectMake(0, 0, 320, 50)];

[self.view addSubview:(_bannerView)];

}

Like @Christophr said, also enable iAd fill rate on the iOS testing device.

That should work. Hope it helps.

Upvotes: 1

chrisamanse
chrisamanse

Reputation: 4319

Import iAd framework, then in your viewcontroller, set self.canDisplayBannerAds = true

Also, check in your device/simulator settings - Settings > Developer > Fill Rate

Choose 100% if you want test ads to always succeed in loading.

Upvotes: 0

Related Questions