Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

iAds in Sprite kit

I have recently finished the Space Cat iPhone app tutorial and would like to add iAds to the game when the "game over" screen appears. How would I go about doing this? Thanks.

1 Answer

It will require you to pull in the iAd framework, then to create a new banner view. From this you can tell the ad to hide or show within your game code.

Start here with the iAd programing guide provided by Apple: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/iAd_Guide/Introduction/Introduction.html

Also other useful resources provided by Apple: https://developer.apple.com/iad/resources/

I am still unsure how to add the iAds. Should they be crafted as nodes?

iAds work by creating a subView of your main view. So no you do not want it to be a node. It is a view of its own that is added to your main view as a subView.

I suggest reading through the apple documentation, they have a large amount of sample code.

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/iAd_Guide/Introduction/Introduction.html

But if you want to create an iAD in landscape here is the code you would use:

ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
[self.view addSubview:adView];

If you save the adView as a property or member of your class then you will be able to hide and show it later on so that it only shows at the end of the game.