2016-08-20 4 views
-1

Ich versuche eine Bannerwerbung in meinem GameOverScene zu implementieren, aber es wird nicht angezeigt (ich bekomme auch keine Fehler).Werbebanner im Spiel über Szene funktioniert nicht - SpriteKit Swift

In GameViewController Ich habe

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 
} 

}

und dann in meinem GameOverScene ich importiert iAd, die AdBannerViewDelegate und ein var

var adBannerView: AdBannerView! 

sowie

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

dann habe ich im Initialisierer showAds aufgerufen.

+3

Das iAd-Netzwerk wurde eingestellt: http://StackOverflow.com/a/37347959/2108547 –

+0

Vielen Dank! Was wird für Anzeigen verwendet? –

+0

Von Apple, nichts. Es gibt jedoch [andere Werbenetzwerke] (https://www.google.com/search?q=ios+ad+networks+for+developers&ie=utf-8&oe=utf-8). –

Antwort

0

iAd ist seit Juli/Juni tot. Sie müssen einen anderen Anzeigenanbieter wie Google AdMob verwenden.

Verwandte Themen