我想在我的swift应用中显示一个奖励广告(Google AdMob)。(XCode 11.4,Swift 5,Storyboard),但每当我加载广告时,它都会在控制台显示以下错误信息。
Error Domain=com.google.admob Code=5
"Request Error: The Google Ad request was unable to be fulfilled before a timeout occurred."
UserInfo={NSLocalizedDescription=Request Error: The Google Ad request was unable to be fulfilled before a timeout occurred., gad_response_info=<GADResponseInfo: 0x6000030f8090>}
我基本上是按照以下教程来做的 谷歌AdMob教程.
info.plist
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GADMobileAds.sharedInstance().start(completionHandler: nil)
}
这就是它的失败之处。
override func viewDidLoad() {
super.viewDidLoad()
rewardedAd = GADRewardedAd(adUnitID: adId)
rewardedAd?.load(GADRequest()) { error in
if let error = error {
print("Error while loading ad: \(error.description)")
// Timeout occurs here!!!
} else {
if self.rewardedAd?.isReady == true {
self.rewardedAd?.present(fromRootViewController: self, delegate:self)
}
}
}
}
知道为什么会超时吗?
注意:我还创建了一个Swift示例。
Error while loading ad: Error Domain=com.google.admob Code=1
"Request Error: No ad to show."
UserInfo={NSLocalizedDescription=Request Error: No ad to show., gad_response_info=<GADResponseInfo: 0x6000018f4d80>}
我在'info.plist'中使用了: ca-app-pub-3940256099942544~1458002511
并为AdID : ca-app-pub-3940256099942544/1712485313
从上面提到的教程页面从谷歌。
我认为你应该用自己的appID与测试广告ID。