1
我一直在使用時,玩家死亡,加載IAD設備間質斯威夫特和雪碧套件做了一個遊戲。但是,廣告有時會延遲,因此在遊戲重新啓動時會在遊戲過程中彈出。有什麼辦法可以解決這個問題嗎?我把從我GameScene使用iAd的間隙:iAd的間質呈現延遲
NSNotificationCenter.defaultCenter().postNotificationName("showInterstitialAd", object: nil)
GameViewController.swift
import UIKit
import SpriteKit
import iAd
class GameViewController: UIViewController, ADBannerViewDelegate, ADInterstitialAdDelegate {
var interstitialAd:ADInterstitialAd!
var interstitialAdView: UIView = UIView()
let transition = SKTransition.fadeWithDuration(1)
var closeButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
override func viewDidLoad() {
super.viewDidLoad()
closeButton.frame = CGRectMake(10, 10, 20, 20)
closeButton.layer.cornerRadius = 10
closeButton.setTitle("x", forState: .Normal)
closeButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
closeButton.backgroundColor = UIColor.whiteColor()
closeButton.layer.borderColor = UIColor.blackColor().CGColor
closeButton.layer.borderWidth = 1
closeButton.addTarget(self, action: "close:", forControlEvents: UIControlEvents.TouchDown)
//loadInterstitialAd()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "loadInterstitialAd", name: "showInterstitialAd", object: nil)
let scene = GameScene(size:CGSize(width: 2208, height: 1242))
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = false
skView.showsNodeCount = false
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFit
scene.anchorPoint = CGPoint(x: 0, y: 0)
skView.presentScene(scene, transition: transition)
}
func close(sender: UIButton) {
closeButton.removeFromSuperview()
interstitialAdView.removeFromSuperview()
interstitialAd.delegate = nil
}
func loadInterstitialAd() {
interstitialAd = ADInterstitialAd()
interstitialAd.delegate = self
}
func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
interstitialAd.delegate = self
interstitialAdView = UIView()
interstitialAdView.frame = self.view.bounds
view.addSubview(interstitialAdView)
view.addSubview(closeButton)
interstitialAd.presentInView(interstitialAdView)
UIViewController.prepareInterstitialAds()
}
func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
closeButton.removeFromSuperview()
interstitialAdView.removeFromSuperview()
}
func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
interstitialAdView.removeFromSuperview()
closeButton.removeFromSuperview()
interstitialAd.delegate = nil
}
func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
closeButton.removeFromSuperview()
interstitialAdView.removeFromSuperview()
interstitialAd.delegate = nil
}
是的,幾乎肯定有辦法解決這個問題。如果你願意分享一些細節,也許我們甚至可以告訴你*如何* ... – stakx
請添加您可能具有的任何相關代碼。 – Tro