我们计划于 2021 年初推出 Google 移动广告 SDK 版本 8.0.0,同时提供一些重大更改,并简单重命名一些 API 以及移除已弃用的 API。
重大更改
关于全屏广告格式 API 的更新
在版本 8.0.0 中,插页式广告、激励广告、插页式激励广告和开屏广告都经过了标准化处理,因此都遵循类似的 API 设计模式。
所有全屏广告格式 API 均采用以下设计:
- 静态加载方法
- 类似的加载回调函数或处理程序机制
- 展示回调函数需要依靠
GADFullScreenContentDelegate
类
如需了解详情,请参阅全屏广告格式迁移指南。
移除了旧版 GADRewardedBasedVideoAd API
新版 GADRewardedAd
API 于 2019 年 3 月首次推出,在之后的 18 个月里一直是首选激励广告 API。与旧版 GADRewardedBasedVideoAd
API 相比,新版 API 包含多项改进,其中包括能够一次加载多个激励广告。
SDK 版本 8.0.0 中移除了该旧版 API。
将智能横幅广告替换为自适应横幅广告
弃用了智能横幅广告,改用自适应横幅广告。自适应横幅广告的效果更好,可以让您更灵活地设置广告宽度。如果您希望继续使用全宽横幅广告,仍然可以通过自适应横幅广告实现,如以下代码段所示:
Swift
class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // Note: The safe area is not known until viewWillAppear. let adSize = getFullWidthAdaptiveAdSize() } func getFullWidthAdaptiveAdSize() -> GADAdSize { // Here safe area is taken into account, hence the view frame is used after the // view has been laid out. let frame = { () -> CGRect in if #available(iOS 11.0, *) { return view.frame.inset(by: view.safeAreaInsets) } else { return view.frame } }() return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width) } }
Objective-C
@implementation ViewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Note: The safe area is not known until viewWillAppear. GADAdSize adSize = [self getFullWidthAdaptiveAdSize]; } - (GADAdSize)getFullWidthAdaptiveAdSize { CGRect frame = self.view.frame; // Here safe area is taken into account, hence the view frame is used after // the view has been laid out. if (@available(iOS 11.0, *)) { frame = UIEdgeInsetsInsetRect(self.view.frame, self.view.safeAreaInsets); } return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width); } @end
移除了退出应用回调函数
移除了所有广告格式的 willLeaveApplication
回调函数,改为使用 的 applicationDidEnterBackground:
和 sceneDidEnterBackground:
方法。
如果使用操作系统级 API,无论用户是否因广告互动而打开您的应用,只要他们退出应用,您都会收到通知。
请注意,千万不要将 willLeaveApplication
回调函数用作广告点击处理程序,如果依赖此类回调函数来报告点击,将无法生成准确的指标。例如,用户点击“广告选择”图标时会启动外部浏览器,这时系统会调用该回调函数,但不会将其计为一次点击。
重命名类
下表列出了版本 8.0.0 中已更改或移除的具体类名称。总结如下:
- 与
GADUnifiedNativeAd
相关的所有类均已重命名为GADNativeAd
。 - 已移除
GADRewardBasedVideoAd
、GADNativeExpressAdView
和GADInstreamAd
。 - 对于所有带
DFP
前缀的类,其前缀均已替换为GAM
。
v7.68.0 中的类 | v8.0.0 中的类 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerViewOptions | GAMBannerViewOptions |
DFPInterstitial | GAMInterstitialAd |
DFPRequest | GAMRequest |
GADRequestError | NSError |
GADUnifiedNativeAdView | GADNativeAdView |
GADUnifiedNativeAd | GADNativeAd |
GADUnifiedNativeAdAssetIdentifiers | GADNativeAdAssetIdentifiers |
GADUnifiedNativeAdDelegate | GADNativeAdDelegate |
GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
GADNativeCustomTemplateAd | GADCustomNativeAd |
GADNativeCustomTemplateAdLoaderDelegate | GADCustomNativeAdLoaderDelegate |
GADNativeAdDelegate | GADCustomNativeAdDelegate |
GADAdLoaderOptions | GADAdOptions |
GADNativeAdMediaAdLoaderOptions | GADNativeAdMediaAdOptions |
GADInAppPurchase | 已移除 |
GADInterstitial | GADInterstitialAd |
GADNativeExpressAdView | 已移除 |
GADRewardBasedVideoAd | 已移除 |
GADInstreamAd | 已移除 |
GADInstreamAdView | 已移除 |
移除/替换的方法
下表列出了版本 8.0.0 中的具体更改。总结如下:
- 移除了先前弃用的方法和属性。
- 移除了所有广告格式的
-willLeaveApplication:
代理方法。 - 广告联盟类名称移到了
GADResponseInfo
属性。 - 测试设备标识符移到了
GADRequestConfiguration
属性。
v7.68.0 中的类 | v7.68.0 中的 API | v8.0.0 中的 API | 备注 |
---|---|---|---|
GADMobileAds | +configureWithApplicationID: | -startWithCompletionHandler: | 现在,在 Info.plist 中设置应用 ID。 |
+disableAutomatedInApp |
-disableAutomatedInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
testDeviceIdentifiers 属性适用于所有广告请求,而旧版 testDevices 属性则是按请求设置的。 |
gender | 已移除 | ||
birthday | 已移除 | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
已移除 | ||
-setLocationWithDescription: | -setLocationWith |
||
-tagForChildDirectedTreatment: | [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment] | ||
GADErrorCode | kGADError* | GADError* | 移除了所有错误代码常量的 k 前缀。
|
GADBannerView | hasAutoRefreshed | autoloadEnabled | |
inAppPurchaseDelegate | 已移除 | ||
mediatedAdView | 已移除 | ||
adNetworkClassName | responseInfo |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerViewOptions | -adSizeDelegate | 已移除 | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDismissScreen: | -banerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillLeaveApplication: | 已移除 | ||
GADNativeCustomTemplateAd | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GADNativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | 已移除 | |
isReady | 已移除 | 改用 canPresentFrom |
|
hasBeenUsed | 已移除 | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | responseInfo |
||
-interstitialWill |
已移除 | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |