2016-08-20 12 views
-1

GameOverScene에 배너 광고를 구현하려고하는데 표시되지 않습니다 (오류도 발생하지 않음).배너 광고 게임 오버 장면이 작동하지 않습니다 - SpriteKit Swift

나는

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

var adBannerView: AdBannerView! 

설정이 GameViewController에서

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

그 다음 이니셜 라이저에서 showAds를 호출했습니다.

+3

iAd 네트워크가 단종되었습니다. http://stackoverflow.com/a/37347959/2108547 –

+0

고맙습니다! 광고에는 무엇이 사용됩니까? –

+0

애플로부터, 아무 것도. 다른 광고 네트워크 (https://www.google.com/search?q=ios+ad+networks+for+developers&ie=utf-8&oe=utf-8)가 있습니다. –

답변

0

iAd는 7 월/6 월 이후 사망합니다. Google AdMob과 같은 다른 광고 제공 업체를 사용해야합니다.