加载我的FB Audience Network横幅广告时出现错误时,为什么我的iAd横幅不显示?

时间:2015-05-20 19:13:49

标签: swift iad facebook-audience-network

我有iAds和Facebook的Audience Network作为我的两个横幅广告。加载我的受众群体广告横幅广告时出错,我希望我的iAd横幅展示。当我尝试在此功能中调用它时,我的iAd横幅不会出现。我在我的设备上测试了这一点,并将开发人员设置填充率设置为0%。我的观众网络广告横幅广告仍会在我执行此操作时显示。我做错了什么?

if (int result = Foo())

1 个答案:

答案 0 :(得分:1)

开发者设置中的填充率仅指 iAd填充率。将其设置为100%。您应该全局创建iAd ADBannerView和FB FBAdView,并在视图加载到viewDidLoad后进行设置。然后,当您的FBAdView无法加载时,您只需将ADBannerView的隐藏属性设置为false即可。现在,您设置的方式是在每次FB ADBannerView无法加载广告时创建新的iAd FBAdView。您的代码应该看起来非常相似:

    // 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)
相关问题