-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に私はIADは、AdBannerViewDelegateを、輸入し、VAR
var adBannerView: AdBannerView!
など
を設定GameViewControllerでfunc showAds(){
NSNotificationCenter.defaultCenter().postNotificationName("showadsID", object: nil)
}
その後、イニシャライザでshowAdsを呼び出しました。
iAdネットワークは廃止されました:http://stackoverflow.com/a/37347959/2108547 –
ありがとう!広告には何が使われますか? –
アップルからは、何もありません。他の広告ネットワーク(https://www.google.com/search?q=ios+ad+networks+for+developers&ie=utf-8&oe=utf-8)もあります。 –