I know there is at least one question asking how to integrate iAd into a sprite kit game, but that is not what I am looking for. I am looking for a portrait version of how t
For those that don't understand, and those that are for future references, here is how I did this to my Sprite Kit game.
I had my game project created using the SpriteKit template in Xcode, then went to the project settings as so:
In the "Link Binary With Libraries" section, just make sure to hit the + button, and add the iAd framework.
After doing that, go to your view controller for your Sprite Kit game, and then type this:
// at the top
#import
// do this in .m, above @implementation
@interface YourViewControllerClassName ()
@property (nonatomic, strong) ADBannerView *banner;
@end
// after the implementation line
// if you're needing to do it horizontally, do:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.banner = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.banner.delegate = self;
[self.banner sizeToFit];
self.canDisplayBannerAds = YES;
SKView *view = (SKView *)self.originalContentView;
SKScene *scene = [[YourScene alloc] initWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
[view presentScene:scene];
}
If you're doing the iAd in just a normal, portrait, you can do the above code, but you can also just use - (void) viewDidLoad instead...
Now is the delegate methods for the iAd to appear...
Go to the code above the @implementation line, and edit it
// do this in .m, above @implementation
@interface YourViewControllerClassName ()
@property (nonatomic, strong) ADBannerView *banner;
@end
Now, go under the implementation line, and enter this:
// NOTE: THIS CODE CAME FROM APPLE MOSTLY
// I DID EDIT IT, BUT THE CREDIT GOES TO APPLE'S DOCUMENTATION
// ON IAD
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (banner.isBannerLoaded) {
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!banner.isBannerLoaded) {
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
}
}
That is all that is required from the iAd to actually work in a SpriteKit game. I hope that I helped those that are going to read this.