Gabriel
Gabriel

Reputation: 171

SWIFT ADMOB : Failed to load: Request Error: No ad to show

I'm actually developing an iOS app with AdMob Reward in Swift and when I try to build my app with the simulator (iPhone 6, 6s, 7, 8...and so on), ads works and I also have this message:

Reward based video ad is received.

But (because there is always a but) when I build my app on my own device (iPhone 6) that doesn't work and I have this error message : "Reward based video ad failed to load: Request Error: No ad to show." This is my code (Obviously I changed Ad Id by the example given in the "Get Started with Reward Ad Mob" but in my app, I use my Ad ID). This the sample ID I choose for the example: 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
    }

And Also

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

Upvotes: 0

Views: 2244

Answers (1)

Yitzchak
Yitzchak

Reputation: 3416

First you should see your logs to get the identifier of your real device

Then fix that line:

request.testDevices = [...]

Replace the ... With the simulator as you did and the if of your real device You then could see a test ad You used your ad unit id instead using your device id

Upvotes: 0

Related Questions