为什么我的admob interstitial在xcode模拟器中工作正常但在我的测试设备上没有(iphone 4s和ipod 5th gen)?

所以我有这个应用程序同时有一个admob横幅广告和一个插页式广告。 横幅在所有屏幕上运行良好。 插页式广告只能在一个屏幕上加载 – 当我在xcode模拟器中测试时,它会正常加载。 但是,当我在我的iPhone和iPod上测试时,兴趣不会加载,我收到此错误:请求错误:收到无效响应。 interstitialDidFailToReceiveAdWithError: 请求错误 :收到无效响应。 有人曾经碰到这个或者可能知道为什么会这样吗? 这是我正在使用的代码:

  // 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() } 

另外,您不应该为局部变量赋予与全局变量相同的名称。