How To Add iAd Banner To SpriteKit Game In Swift

Today I’m gonna show you how to add iAd banner to SpriteKit game in Swift. Again, there’s a ton of tutorials how to add iAds normal iOS app, but in case of SpriteKit game and Swift, it wasn’t so obvious to me. For further info, here’s the official guide. To quickly sum-up basics:

  1. You need to enroll in Apple iOS Developer program (99$/year) if you want to use iAds in your apps.
  2. You need to add iAd.framework to your project at Linked Frameworks and Libraries section of Project settings.
  3. Finally add “import iAd” to your class and conform to the protocol ADBannerViewDelegate like this:

Why am I using AppDelegate class? I want to display iAd banner at many places, not just one scene, so it’d be nice to have only one instance of banner, and just show it or hide it when necessary. To tell AppDelegate to show or hide banner, I’m using NSNotificationCenter:

This tells AppDelegate to listen for notification with selectors showiAdBanner and hideiAdBanner.  

For my banner I have declared variable inside AppDelegate class:

And here are my methods, which will be called whenever AppDelegate receives proper notification:

Last methods is not mandatory, but it should be included in case there is some error with loading iAd banner. If this happens, it will be called automatically.

And so now, if game is displaying some menu screen for example, and I want to display iAd banner, I just call this in that menu scene:

It was easy to integrate iAd banner to my game after all. Thanks for reading!