当加载我的 FB Audience Network 横幅广告时出现错误,为什么我的 ipAd 横幅没有出现?

Why doesn't my iAd banner appear when theres an error loading my FB Audience Network banner ad?

我有 iAds 和 Facebook 的 Audience Network 作为我的两个横幅广告。当加载我的 Audience Network 横幅广告时出现错误,我希望显示我的 iAd 横幅。当我尝试在此函数中调用它时,我的 iAd 横幅没有出现。我正在我的设备上对此进行测试,并将开发人员设置填充率设置为 0%。当我这样做时,我的 Audience Network 的横幅广告仍然显示。我做错了什么?

class GameViewController: UIViewController, ADBannerViewDelegate,
        ADInterstitialAdDelegate, SKProductsRequestDelegate,
    SKPaymentTransactionObserver, ChartboostDelegate, FBAdViewDelegate {

    var productID: NSString!
    let defaults = NSUserDefaults.standardUserDefaults()

    override func viewDidLoad() {
        super.viewDidLoad()
        if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = false
            skView.showsNodeCount = false
            skView.multipleTouchEnabled = true

            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = SKSceneScaleMode.AspectFill
            //scene.size = skView.bounds.size
            skView.presentScene(scene)
            loadFbAds()
        }

        func loadFbAds() {
            if defaults.boolForKey("removeAdsPurchased") == false {
                let width = self.view.frame.size.width
                let height = self.view.frame.size.height / 10

                let adView: FBAdView = FBAdView(placementID:"placement_id", adSize:kFBAdSize320x50, rootViewController:self)
                adView.frame = CGRect(x: 0, y: self.view.frame.size.height - 50, width: width, height: height)
                self.view.addSubview(adView)

                adView.delegate = self
                FBAdSettings.addTestDevice("testdevice")
                adView.loadAd()

                println("worksssssssssfsdfsdfsdfsdf")
            }
        }

        func adView(adView: FBAdView!, didFailWithError error: NSError!) {
            adBannerView = ADBannerView(frame: CGRect.zeroRect)
            adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
            adBannerView.delegate = self
            adBannerView.hidden = false
            view.addSubview(adBannerView)

            adView.hidden = true
        }
}

您的开发者设置中的填充率仅指您的 iAd 填充率。将此设置为 100%。您应该在全球范围内创建 iAd ADBannerView 和 FB FBAdView,并在您的 viewDidLoad 中加载视图后设置它们。然后,当您的 FB FBAdView 加载失败时,您可以将 ADBannerView 的隐藏 属性 设置为 false。按照您现在设置的方式,您将在每次 FB FBAdView 无法加载广告时创建一个新的 iAd ADBannerView。您的代码最终应该看起来与此非常相似:

    // Create our FB and iAd banners globally
    var fbBannerAd: FBAdView = FBAdView()
    var iAdBannerAd: ADBannerView = ADBannerView()

override func viewDidLoad() {
    super.viewDidLoad()

    // View loaded so lets setup our ads
    setupAds()
}

func setupAds() {
    // FB
    // Create FB banner ad with our placementID and select an adSize
    fbBannerAd = FBAdView(placementID:"placementID", adSize:kFBAdSizeHeight50Banner, rootViewController:self)
    // Set its frame relative to the screen
    fbBannerAd.frame = CGRect(x: 0, y: self.view.frame.size.height - fbBannerAd.frame.height, width: self.view.frame.size.width, height: fbBannerAd.frame.height)
    // Request ad from FB
    fbBannerAd.loadAd()
    // Set our ads delegate to 'self'
    fbBannerAd.delegate = self
    // Add our FB ad to our view
    self.view.addSubview(fbBannerAd)

    // iAd
    // Set its frame relative to the screen
    iAdBannerAd.frame = CGRect(x: 0, y: self.view.frame.size.height - iAdBannerAd.frame.height, width: self.view.frame.size.width, height: iAdBannerAd.frame.height)
    // Set our ads delegate to 'self'
    iAdBannerAd.delegate = self
    // Add our iAd ad to our view
    self.view.addSubview(iAdBannerAd)
    // Lets hide our iAd ad initially
    iAdBannerAd.hidden = true

    println("created our banner ads")
}

func adView(adView: FBAdView!, didFailWithError error: NSError!) {
    // FB ad failed to load
    // Lets print the error so we know why
    println("failed to load fb ad with error: \(error)")

    // Also lets hide our FB ad because it doesn't have an ad to show
    fbBannerAd.hidden = true

    // And now we show our iAd ad
    iAdBannerAd.hidden = false
}

func adViewDidLoad(adView: FBAdView!) {
    // FB ad loaded an ad
    // Lets make sure it is shown and our iAd ad is hidden
    fbBannerAd.hidden = false
    iAdBannerAd.hidden = true
}

然后,要查看当您的 FB FBAdView 失败时会发生什么,您可以调用:

adView(fbBannerAd, didFailWithError: nil)