Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 来自iAd的间隙广告是';我不想在swift上工作_Xcode_Swift_Iad_Interstitial - Fatal编程技术网

Xcode 来自iAd的间隙广告是';我不想在swift上工作

Xcode 来自iAd的间隙广告是';我不想在swift上工作,xcode,swift,iad,interstitial,Xcode,Swift,Iad,Interstitial,我试图实现间隙广告,但我的代码似乎不工作 class ViewController: UIViewController, ADInterstitialAdDelegate { var interAd = ADInterstitialAd() var interAdView: UIView = UIView() var closeButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton override func vi

我试图实现间隙广告,但我的代码似乎不工作

class ViewController: UIViewController, ADInterstitialAdDelegate {

var interAd = ADInterstitialAd()
var interAdView: UIView = UIView()
var closeButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton

override func viewDidAppear(animated: Bool) {

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)
loadAd()
}
func close(sender: UIButton) {
    closeButton.removeFromSuperview()
    interAdView.removeFromSuperview()
}
func loadAd() {
    println("load ad")
    interAd = ADInterstitialAd()
    interAd.delegate = self
}

func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
    println("ad did load")

    interAdView = UIView()
    interAdView.frame = self.view.bounds
    view.addSubview(interAdView)

    interAd.presentInView(interAdView)
    UIViewController.prepareInterstitialAds()

    interAdView.addSubview(closeButton)
}

func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {

}

func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
    println("failed to receive")
    println(error.localizedDescription)

    closeButton.removeFromSuperview()
    interAdView.removeFromSuperview()

}
}

广告没有出现,出于某种原因,应用程序甚至在跟踪“广告确实加载”,但广告没有出现。有时我会遇到这样的错误:xCode告诉我,一次显示的广告超过10个,但我甚至没有看到一个广告。这会是什么问题?如果有人能告诉我如何在关卡结束后让广告出现,那也是一件好事,但如果你不能,那就一切都好了。谢谢你的帮助

我创建了一个新场景,并将其添加到文件中:

class Advertisement11: SKScene, ADInterstitialAdDelegate {
    var interAd = ADInterstitialAd()
    var interAdView = UIView()
    var closeButton = UIButton()
    var returnToScene = SKScene()

    override func didMoveToView(view: SKView) {
        closeButton.frame = CGRectMake(20, 20, 30, 30)
        closeButton.layer.cornerRadius = 15
        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)
        loadAd()
    }

    func close(sender: UIButton) {
        closeButton.removeFromSuperview()
        interAdView.removeFromSuperview()
        let block = SKAction.runBlock {
            self.view?.presentScene(self.returnToScene)
        }
        self.runAction(block)//this is to go back to the previous Scene
    }

    func loadAd() {
        print("load ad")
        interAd = ADInterstitialAd()
        interAd.delegate = self
    }

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        print("ad did load")

        interAdView = UIView()
        interAdView.frame = self.view!.frame
        view!.addSubview(interAdView)

        interAd.presentInView(interAdView)
        UIViewController.prepareInterstitialAds()

        interAdView.addSubview(closeButton)
    }

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {

    }

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
        print("failed to receive")
        print(error.localizedDescription)

        closeButton.removeFromSuperview()
    //  interAdView.removeFromSuperview()
    }
}
检查我的答案。自从它们在iPhone上推出以来,我一直无法可靠地实现它们。就个人而言,如果你不介意与另一个广告网络打交道,我建议你使用AdMob interstitials。更可靠,填充率更高。