-1

I am trying to implement a banner ad in my GameOverScene but it is not displaying (I'm not getting any errors either).

In GameViewController I have

import UIKit
import SpriteKit
import iAd

class GameViewController: UIViewController, ADBannerViewDelegate {


var SH = UIScreen.mainScreen().bounds.height
let transition = SKTransition.fadeWithDuration(1)
var UIiAd: ADBannerView = ADBannerView()


override func viewDidLoad() {

    super.viewDidLoad()

    self.UIiAd.hidden = true
    self.UIiAd.alpha = 0

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.hideBannerAd), name: "hideadsID", object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.showBannerAd), name: "showadsID", object: nil)


    let scene = GameScene(size: view.bounds.size)
    let skView = view as! SKView
    print(view.bounds.size.height)
    print(view.bounds.size.width)
    skView.showsFPS = true
    skView.showsNodeCount = true
    skView.ignoresSiblingOrder = true
    scene.scaleMode = .ResizeFill
    //skView.showsPhysics = true


    skView.presentScene(scene)
    skView.showsPhysics = false


}


override func viewWillAppear(animated: Bool) {
    let BV = UIiAd.bounds.height
    UIiAd.delegate = self
    UIiAd.frame = CGRectMake(0, SH + BV, 0, 0)
    self.view.addSubview(UIiAd)
}

override func viewWillDisappear(animated: Bool) {
    UIiAd.delegate = nil
    UIiAd.removeFromSuperview()
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    let _ = UIiAd.bounds.height
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1) // Time it takes the animation to complete
    UIiAd.alpha = 1 // Fade in the animation
    UIView.commitAnimations()
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1)
    UIiAd.alpha = 0
    print("didnt work")
    UIView.commitAnimations()
}

func showBannerAd() {
    UIiAd.hidden = false
    let BV = UIiAd.bounds.height

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1) // Time it takes the animation to complete
    UIiAd.frame = CGRectMake(0, SH - BV, 0, 0) // End position of the animation
    UIView.commitAnimations()
}

func hideBannerAd() {
    UIiAd.hidden = true
    let BV = UIiAd.bounds.height

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1) // Time it takes the animation to complete
    UIiAd.frame = CGRectMake(0, SH + BV, 0, 0) // End position of the animation
    UIView.commitAnimations()
}



override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

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

}

and then in my GameOverScene I imported iAd, the AdBannerViewDelegate, and set up a var

var adBannerView: AdBannerView!

as well as

func showAds(){
    NSNotificationCenter.defaultCenter().postNotificationName("showadsID", object: nil)
}

then I called showAds in the initializer.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Connor V
  • 231
  • 3
  • 15

1 Answers1

0

iAd is dead since July/June. You will have to use another ad provider like google AdMob.

crashoverride777
  • 10,581
  • 2
  • 32
  • 56