为什么我的AdMob插页广告在Xcode模拟器上工作得很好,但在我的测试设备上却不行?



我有一个应用程序,它既有admob横幅广告,也有插播式广告。这条横幅在所有屏幕上都能正常运行。

插页式广告只应该在一个屏幕上加载——当我在Xcode模拟器中测试它时,它加载得很好。但当我在iPhone 4S和iPod Touch第5代上测试时,插页广告无法加载,我得到了这个错误:

& lt; Google>请求错误:收到无效的响应。interstitialDidFailToReceiveAdWithError: 请求错误: Received invalid response.

有没有人遇到过这种情况,或者知道为什么会发生这种情况?

下面是我正在使用的代码:

   // interstitial ad variable...
var interstitial: GADInterstitial?
var timer:NSTimer?
var loadRequestAllowed = true
let screen = UIScreen.mainScreen().bounds
let IS_IPAD = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad
var buttonHeight:CGFloat = 0.0
var buttonOffsetY:CGFloat = 0.0
let statusbarHeight:CGFloat = 20.0
var iAdSupported = false

       // load the interstitial
    //Admob Interstitial
    buttonHeight = IS_IPAD ? 30 : 20
    buttonOffsetY = statusbarHeight
    if !iAdSupported {
        interstitial = createAndLoadInterstitial()
    } // closes if !iAdSupported
 
//        presentInterstitial()
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target:self, selector: Selector("presentInterstitial"), userInfo: nil, repeats: false)
    println("the timer made presentInterstitial run")


 //Interstitial func
func createAndLoadInterstitial()->GADInterstitial {
    println("createAndLoadInterstitial")
    var interstitial = GADInterstitial(adUnitID: "ca-app-pub-4471013071748494/2225255714")
    
    interstitial.delegate = self
    interstitial.loadRequest(GADRequest())
    
    return interstitial
} // closes createAndLoadInterstitial …
func presentInterstitial() {
    if let isReady = interstitial?.isReady {
        interstitial?.presentFromRootViewController(self)
        println("presentInterstitial function ran")
    } // closes if let isReady
} // closes presentInterstitial …

//Interstitial delegate
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
    println("interstitialDidFailToReceiveAdWithError:(error.localizedDescription)")
    //  ResultsBtn?.enabled = false
    interstitial = createAndLoadInterstitial()
} // closes interstitial …

你试图在它有机会加载之前呈现你的插页广告。你的timer在一秒后发射func presentInterstitial。将其更改为较大的数字,以提供加载的间隔时间。

import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADInterstitialDelegate {
    
    var admobInterstitial : GADInterstitial?
    var timer : NSTimer?
    override func viewDidLoad() {
        super.viewDidLoad()
        
        admobInterstitial = createAndLoadInterstitial()
        timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target:self, selector: Selector("presentInterstitial"), userInfo: nil, repeats: false)
    }
 
    func createAndLoadInterstitial()->GADInterstitial {
        var interstitial = GADInterstitial(adUnitID: "yourAdMobADUnitID")
        interstitial.delegate = self
        interstitial.loadRequest(GADRequest())
        return interstitial
    }
    
    func presentInterstitial() {
        if let isReady = admobInterstitial?.isReady {
            admobInterstitial?.presentFromRootViewController(self)
        }
    }
    
    func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
        println("interstitialDidFailToReceiveAdWithError:(error.localizedDescription)")
        admobInterstitial = createAndLoadInterstitial()
    }

相关内容

最新更新