我实际上是在 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!