How to create a iAd banner?

165 views Asked by At

I'm still a noob developper and I just finished my little game and now I want to integrate AdBanner.

With the code bellow the banner appear and disappear instantly. I tried on another ViewController/GameScene and the banner appear and stay. I can't understand the problem.

My Game is under gravity. It is to shoot falling objects from the bottom of the screen.

Someone can help me ?

Here my GameViewController code :

import UIKit
import SpriteKit
import AVFoundation
import iAd

var defaults = NSUserDefaults()
var highscore = defaults.integerForKey("highscore")


class GameViewController: UIViewController {



override func viewDidLoad() {
    super.viewDidLoad()

    self.canDisplayBannerAds = true

    var skView = self.originalContentView as SKView
    var scene:SKScene = GameScene(size: skView.bounds.size)

    skView.showsFPS = false
    skView.showsNodeCount = false
    skView.showsPhysics = false

    let turbulence = SKFieldNode.turbulenceFieldWithSmoothness(0.1, animationSpeed: 0.1)
    scene.addChild(turbulence)
    let noise = SKFieldNode.turbulenceFieldWithSmoothness(0.4, animationSpeed: 0.1)
    scene.addChild(noise)

    skView.presentScene(scene)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override func prefersStatusBarHidden() -> Bool {
    return true
}
}
1

There are 1 answers

10
Wiem On BEST ANSWER

You can add the iAd framework into the project. Then link it into your file with:

import iAd

Then you add this line of code whenever you want the ad to come onto the screen:

self.canDisplayBannerAds = true

This will automatically give you an add at the bottom of the screen.