iAD没有按预期工作

时间:2015-02-24 01:16:32

标签: ios iphone swift iad

我设置了插页式广告,如果用户死了4次,则会弹出整页广告。每次玩家死亡时,numberOfLoses都会增加。

        numberOfLosses++
        if numberOfLosses == 4 {
            gameViewController?.showFullScreenAd()
            numberOfLosses = 0
        }

第一次在模拟器和我的设备上工作,但是无论我死多少次,我都再也看不到它了。这个东西一旦在应用程序商店上运行,或者我做错了吗?

 func showFullScreenAd() {
        interstitial.delegate = self
        self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Manual
        self.requestInterstitialAdPresentation()
}

如果我println(self.requestInterstitialAdPresentation())我第一次得到假

这是我更新的代码(可以同时加载多个广告)

 //MARK: interstitial ad delegate

func showFullScreenAd() {
    viewForAd = UIView(frame: screenbounds)
    viewForAd.frame = CGRectOffset(viewForAd.frame, 0, screenbounds.size.height)
    self.view.addSubview(viewForAd)

    iADInterstitial = ADInterstitialAd()
    iADInterstitial.delegate = self
    self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Manual
    self.requestInterstitialAdPresentation()
}

func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
    iADInterstitial = nil
    println("did unload")

}

func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
    viewForAd.removeFromSuperview()
    viewForAd = nil
    iADInterstitial = nil
    println("failed with error: \(error.localizedDescription)")

}

func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
    println("Ad did load")
    iADInterstitial.presentInView(viewForAd)
    UIView.beginAnimations("", context: nil)
    viewForAd.frame = CGRectOffset(viewForAd.frame, 0, -screenbounds.size.height)
    UIView.commitAnimations()
}

func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
    UIView.beginAnimations("", context: nil)
    viewForAd.frame = CGRectOffset(viewForAd.frame, 0, screenbounds.size.height)
    UIView.commitAnimations()
    println("action did finish")
}

1 个答案:

答案 0 :(得分:2)

您不需要interstitial.delegate = self(以及您未展示的任何其他代码。)

您只需要两到三行代码:

// Preloads an ad, so call on app startup (optional but recommended).
[UIViewController prepareInterstitialAds];

// Call once on your viewController when you create it.
self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;

// Call when you want to show an ad (will show if one is available)
[self requestInterstitialAdPresentation];

这就是iOS 7中的所有新方法。无论你有什么其他代码都可能导致问题所以删除它,如果你仍然有问题(特别是在100%填充率的测试中),那么需要进一步调查。