0

我实际上是在 Swift 中使用 AdMob Reward 开发 iOS 应用程序,当我尝试使用模拟器(iPhone 6、6s、7、8...等)构建我的应用程序时,广告可以正常工作,并且我也收到以下消息:

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

但是(因为总是有一个但是)当我在我自己的设备(iPhone 6)上构建我的应用程序时它不起作用并且我有这个错误消息:“基于奖励的视频广告未能加载:请求错误:没有广告显示。” 这是我的代码(显然,我通过“开始使用 Reward Ad Mob”中给出的示例更改了广告 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!
4

1 回答 1

0

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

然后修复该行:

request.testDevices = [...]

将...替换为您所做的模拟器和真实设备的 if 然后您可以看到一个测试广告您使用了您的广告单元 ID而不是使用您的设备 ID

于 2017-10-25T14:33:41.343 回答