简体   繁体   English

iAd未加载广告xcode7

[英]iAd not loading ads xcode7

I've used the same code on all my apps to display iAd ads, but after downloading xcode 7 and converting my code to swift2, ads don't appear anymore on my device or on the xcode simulator. 我在我的所有应用上使用相同的代码来显示iAd广告,但在下载xcode 7并将我的代码转换为swift2后,广告不再出现在我的设备或xcode模拟器上。 Does anyone know what changes need to be made? 有谁知道需要做出哪些改变?

import UIKit
import SpriteKit
import iAd
class GameViewController: UIViewController, ADBannerViewDelegate {

    var adBanner: ADBannerView? = ADBannerView()

    override func viewDidLoad() {
        super.viewDidLoad()

        adBanner?.delegate = self

        adBanner?.hidden = true

        self.canDisplayBannerAds = true     

    }

    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
        adBanner?.hidden = true

    }

    func bannerViewDidLoadAd(banner: ADBannerView!) {
        adBanner?.hidden = false

    }

    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
        return willLeave
    }

}

You are mixing up two approaches. 你正在混淆两种方法。 There are two ways of displaying iAd banners. 有两种显示iAd横幅的方式。 First one, just let iAd know that you want do show banners on your view controller and let iAd do the rest. 首先,让iAd知道你想要在你的视图控制器上显示横幅,让iAd完成其余的工作。 This is done by calling the following method: 这是通过调用以下方法完成的:

    self.canDisplayBannerAds = true     

Second approach is to load the banner first and then add it manually to your view. 第二种方法是先加载横幅,然后手动将其添加到视图中。 To do that, you first initialise the banner with the desired type and set its delegate: 为此,首先使用所需类型初始化横幅并设置其委托:

var adBanner: ADBannerView? = ADBannerView(adType: ADAdType.Banner)
adBanner?.delegate = self

Then, when the banner is loaded, we have to add it to a view, for example: 然后,当加载横幅时,我们必须将其添加到视图中,例如:

func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.view.addSubview(banner)
}

There is no need to change the hidden property before the banner i added to superview. 在我添加到superview的横幅之前,无需更改hidden属性。

Have you considered iAd network to be down at the very moment? 你有没有考虑过iAd网络暂时关闭? Always keep a copy of Apples own iAd Suite at hand: https://developer.apple.com/library/ios/samplecode/iAdSuite_Storyboard/Introduction/Intro.html 随时保留Apples自己的iAd Suite副本: https//developer.apple.com/library/ios/samplecode/iAdSuite_Storyboard/Introduction/Intro.html

If their own dont't load, yours won't load either. 如果他们自己没有加载,你的也不会加载。

Right now I'm getting this self explanatory error message: 现在我收到这个自我解释的错误信息:

NSLocalizedFailureReason=Ad inventory unavailable

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM