0

I'm very new to the IOS dev with Swift, and just building one game apps using SpriteKit. I have been trying/searching for implementing/putting the iAd banner on the apps - but not all the time, only on the GameOverScene. The game apps have an opening scene, then user will click to start the game, then once the game ended, the GameOverScene will appear with score etc. and also the iAd banner at the bottom (in portrait mode only).

searching in Apple developer didn't returns expected results - only sample codes in Obj-C instead of swift. anyone can provide sample codes/links/guides ?

Any help are greatly appreciated.

Thanking you in advanced.

best regards,

--

Kerjaluar
  • 5
  • 1
  • sorry my bad.. I follow the guide from (http://stackoverflow.com/questions/24771295/iad-in-xcode-6-with-swift) and got it working fine on the game apps, only need to use adBannerView.hidden = true/false everytime you need to display/hide it... – Kerjaluar Dec 08 '14 at 15:50

1 Answers1

0

Import the iAd framework and make sure you have this line in your GameOverScene:

import iAd

Use this code to open the iAd banner:

func loadAds()->ADBannerView{
    adBannerView = ADBannerView(frame: CGRect.zeroRect)
    adBannerView.center = CGPoint(x: adBannerView.center.x, y: view!.frame.size.height - adBannerView.frame.size.height / 2)
    adBannerView.delegate = self
    self.view?.addSubview(adBannerView)
    return adBannerView
}

When you move to another scene simple implement this line:

adBannerView.hidden = true

Then the banner will disappear when you move to another scene. These are some extra functions you may need:

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("Ad could not load. Probably a network error.")
    self.adBannerView.hidden = true
}
 func bannerViewDidLoadAd(banner: ADBannerView!) {
    println("Ad did load")
    self.adBannerView.hidden = false
}
TheCodeComposer
  • 725
  • 5
  • 17