0

How can i place an iAd Banner at the Top of the View in a SpriteKit Application?

The Banner is working perfectly but on the wrong position.

Here is the code for the iAd Banner, but the its always below:

ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.originalContentView;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

    // Create and configure the scene.
    SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    self.canDisplayBannerAds = YES;

    // Present the scene.
    [skView presentScene:scene];

}
Larme
  • 24,190
  • 6
  • 51
  • 81
  • 2
    Use viewWillLayoutSubviews to present the first scene, search SO or google for proper solution. Otherwise bounds.size will be incorrect for landscape apps. – CodeSmile May 01 '14 at 19:06
  • There is a previous SO answer on this subject here http://stackoverflow.com/questions/21669567/iad-in-sprite-kit-game – sangony May 01 '14 at 21:51

1 Answers1

2

I can't tell from the code you posted how much you have implemented already, so for completeness...

Import iAd

@import iAd;

My preference has been to just create the ADBannerView class variable as a private instance iVar.

@implementation ViewController {
    ADBannerView *_bannerView;
}

Then in viewDidLoad

-(void)viewDidLoad {
    // iAd support
    _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
    _bannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _bannerView.delegate = self;
    [self.view addSubview:_bannerView];
}

For an iAd banner that displays across the top of the screen, this has been all that is required to get it to show up on screen.

For the delegate methods, my current strategy is to hide the banner when it doesn't have anything to display.

#pragma mark - iAd Methods
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    _bannerView.hidden = NO;
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    _bannerView.hidden = YES;
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
    return YES;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
}
jgnovak-dev
  • 495
  • 3
  • 11