SWIFT ADMOB:无法加载:请求错误:无广告显示

时间:2017-10-25 14:22:25

标签: ios swift admob rewardedvideoad

我实际上正在使用Swift中的AdMob Reward开发iOS应用程序,当我尝试使用模拟器(iPhone 6,6s,7,8等等)构建我的应用程序时,广告可以正常运行也有这样的信息:

  

收到基于奖励的视频广告。

但是(因为总有一个但是)当我在我自己的设备(iPhone 6)上构建我的应用程序时,它没有工作,我有这个错误消息: "基于奖励的视频广告无法加载:请求错误:无广告显示。" 这是我的代码(显然我通过" Getward with Reward Ad Mob&#34中给出的示例更改了广告ID;但在我的应用中,我使用了我的广告ID)。这是我为示例选择的样本ID:ca-app-pub-3940256099942544/1712485313

let request = GADRequest()
    request.testDevices = [ kGADSimulatorID,"ca-app-pub-3940256099942544/1712485313"];
    rewardBasedVideo = GADRewardBasedVideoAd.sharedInstance()
    rewardBasedVideo?.delegate = self
    if rewardBasedVideo?.isReady == false {
        rewardBasedVideo?.load(GADRequest(), withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
        adRequestInProgress = true
    }

//ADMOB
// MARK: GADRewardBasedVideoAdDelegate implementation
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
                        didFailToLoadWithError error: Error) {
    adRequestInProgress = false
    print("Reward based video ad failed to load: \(error.localizedDescription)")
}

func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    adRequestInProgress = false
    print("Reward based video ad is received.")
}

func rewardBasedVideoAdDidOpen(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    print("Opened reward based video ad.")
}

func rewardBasedVideoAdDidStartPlaying(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    print("Reward based video ad started playing.")
}

func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    print("Reward based video ad is closed.")
}

func rewardBasedVideoAdWillLeaveApplication(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    print("Reward based video ad will leave application.")
}

func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
                        didRewardUserWith reward: GADAdReward) {
    print("Reward received with currency: \(reward.type), amount \(reward.amount).")
}
//ADMOB!

1 个答案:

答案 0 :(得分:0)

首先,您应该看到您的日志以获取您的真实设备的标识符

然后修复该行:

request.testDevices = [...]

替换...使用您所做的模拟器和您的真实设备的if 然后,您可以看到测试广告 您使用设备ID 来使用广告单元ID