Ios 为什么我的admob Interstitual在xcode模拟器中运行良好,但在我的测试设备(iphone 4s和ipod 5th gen)上运行不正常?

Ios 为什么我的admob Interstitual在xcode模拟器中运行良好,但在我的测试设备(iphone 4s和ipod 5th gen)上运行不正常?,ios,xcode,swift,admob,interstitial,Ios,Xcode,Swift,Admob,Interstitial,因此,我有一个应用程序,既有admob横幅广告,也有插页广告。横幅在所有屏幕上都可以正常运行。间隙式ad应该只在一个屏幕上加载——当我在xcode模拟器中测试它时,它加载良好。但是,当我在iPhone和iPod上测试时,没有加载Interestial,我得到了以下错误:请求错误:收到无效响应。 InterstitialIDFailToReceiveADWithError:请求错误:收到无效响应。 以前有没有人遇到过这种情况,或者知道为什么会发生这种情况? 以下是我正在使用的代码: // i

因此,我有一个应用程序,既有admob横幅广告,也有插页广告。横幅在所有屏幕上都可以正常运行。间隙式ad应该只在一个屏幕上加载——当我在xcode模拟器中测试它时,它加载良好。但是,当我在iPhone和iPod上测试时,没有加载Interestial,我得到了以下错误:请求错误:收到无效响应。
InterstitialIDFailToReceiveADWithError:
请求错误:收到无效响应。 以前有没有人遇到过这种情况,或者知道为什么会发生这种情况? 以下是我正在使用的代码:

   // 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 …

您正试图在间隙有机会加载之前呈现间隙。您的
计时器
在一秒钟后触发
func presentinterstital
。将此值更改为更大的数值,以给间隙加载时间

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

另一方面,您不应该为局部变量指定与全局变量相同的名称。

您试图在间隙变量有机会加载之前将其显示出来。您的
计时器
在一秒钟后触发
func presentinterstital
。将此值更改为更大的数值,以给间隙加载时间

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

另一方面,您不应为局部变量指定与全局变量相同的名称。

请确保您的AdMob Ad Unit ID与AdMob提供给您的ID完全相同。谢谢!是的,我有。。。所有这些都是合法的。请确保您的AdMob广告单位ID与AdMob提供给您的完全相同。谢谢!是的,我有。。。这都是合法的。哇。。。事情总是简单的。你说得对。我把计时器调高到5,它工作了。。。3岁的时候还在工作。呜!非常感谢。在旁注上。。。哎呀!我有罪。再次感谢!哇!事情总是简单的。你说得对。我把计时器调高到5,它工作了。。。3岁的时候还在工作。呜!非常感谢。在旁注上。。。哎呀!我有罪。再次感谢!