Displaying banner ads with SpriteKit
Asked Answered
S

1

4

I'm new to SpriteKit and just published my first game. Now I would like to add banner ads to the game. However, I'm completely lost.

Most tutorials tell you to simply call

self.canDisplayBannerAds = YES;

in the viewDidLoad method. I'm doing that, and I also imported iAD.h and linked the required binaries. However, everytime I start the game it crashes and gives me the following error:

-[UIView presentScene:transition:]: unrecognized selector sent to instance 0x15e2dd00

Does anybody know a good tutorial or any ideas on how to correctly implement iADs into a Sprite Kit game? Apple Docs wasn't really helpful either.

Showcase answered 16/2, 2014 at 21:11 Comment(0)
T
4

I had honestly just figured this out not that long ago because I too was completely lost! What you need to do is

1: Link the iAd framework into your project

Then, go to your ViewController class, and inside the .m file, do the following

#import <iAd/iAd.h>

- (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 = [SKSceneClass sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;

self.canDisplayBannerAds = YES;

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

or if you are doing a horizontal application, change viewDidLoad with viewWillLayoutSubviews

That is all that is required :) Hope that helps!

Trim answered 16/2, 2014 at 21:16 Comment(2)
Thanks, it worked! Instead of SKView * skView = (SKView *)self.originalContentView; I had something like SKView * skView = (SKView *)[self size] which caused the crash.Showcase
Yea, iAd was very confusing for a couple weeks for me! :)Trim

© 2022 - 2024 — McMap. All rights reserved.