我刚刚将 Google 移动广告 SDK 升级到 8.0 版,但出现此错误:
<块引用>在范围内找不到类型“GADInterstitial”
我也将此代码添加到 AppDelegate:
GADMobileAds.sharedInstance().start(completionHandler: nil)
Google 移动广告 SDK 运行良好,直到我升级到 8.0 版
注意:我也在我的应用中使用 Firebase 框架。
答案 0 :(得分:4)
这是 Admob Interstitial 的代码,只能复制粘贴 我刚刚将 Google 移动广告 SDK 升级到 8.0 版
导入 GoogleMobileAds 类 ViewController:UIViewController、GADFullScreenContentDelegate{
Match (x1:A)
with x1
optional Match (x1)-[:A_B]-(x2:B)
with x1 , collect(x2) as nodes, count(x2) as x3
where x1.foo= 'bar' and (x3 = 1)
UNWIND nodes as x2
return DISTINCT x1 as A
SKIP 0
LIMIT 10
}
答案 1 :(得分:2)
Google 在没有告诉任何人的情况下更新了 SDK。 查看 Admob 上关于添加插页式广告的新指南。 本质上,GADInterstitial 已更改为 GADInterstitialAd,您也必须使用不同的委托。
感谢 Google。
答案 2 :(得分:2)
Google 移动广告 SDK 8.0 的 API 接口发生了巨大变化。请参阅 Google 的 official document for Interstitial。为了使其完整,这里是对 8.0 之前的 legacy API 的参考。
主要变化是委托和广告类:
旧 | 新 |
---|---|
GADInterstitialDelegate | GADFullScreenContentDelegate |
GADInterstitial | GADInterstitialAd |
而不是以传统方式初始化广告:
interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
let request = GADRequest()
interstitial.load(request)
现在以如下方式初始化
let request = GADRequest()
GADInterstitialAd.load(withAdUnitID:"ca-app-pub-3940256099942544/4411468910",
request: request,
completionHandler: { [self] ad, error in
if let error = error {
print("Failed to load interstitial ad with error: \(error.localizedDescription)")
return
}
interstitial = ad
interstitial?.delegate = self
}
以及新的 GADFullScreenContentDelegate 方法:
/// Tells the delegate that the ad failed to present full screen content.
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
print("Ad did fail to present full screen content.")
}
/// Tells the delegate that the ad presented full screen content.
func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did present full screen content.")
}
/// Tells the delegate that the ad dismissed full screen content.
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did dismiss full screen content.")
}
请注意,不再有 interstitialDidReceiveAd
方法。相反,您要么开始在 GADInterstitialAd.load()
完成回调中展示广告,要么在稍后阶段展示已初始化的广告:
if interstitial != nil {
interstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
}