2016-08-20 8 views
-1

Я пытаюсь реализовать баннерное объявление в своем GameOverScene, но оно не отображается (я тоже не получаю никаких ошибок).Объявление баннера в игре над сценой не работает - SpriteKit Swift

В GameViewController У меня есть

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 
} 

}

, а затем в моем GameOverScene я импортировал ОВР, тем AdBannerViewDelegate и создать вар

var adBannerView: AdBannerView! 

, а также

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

, тогда я вызвал showAds в инициализаторе.

+3

Сеть iAd была прекращена: http://stackoverflow.com/a/37347959/2108547 –

+0

Спасибо! Что будет использоваться для рекламы? –

+0

От Apple ничего. Существуют [другие рекламные сети] (https://www.google.com/search?q=ios+ad+networks+for+developers&ie=utf-8&oe=utf-8). –

ответ

0

iAd мертв с июля по июнь. Вам придется использовать другой рекламный агент, такой как Google AdMob.