本文介绍了现行版本和以往版本的 Google Mobile Ads SDK for iOS 的迁移。我们预计将于 2026 年 2 月发布 13.0.0 版。
从 v12 迁移到 v13
提高了最低部署目标
最低部署目标版本已提高到 iOS 13。
锚定自适应横幅广告尺寸 API 的变更
13.0.0 版弃用了现有的锚定自适应横幅广告尺寸 API,并引入了大型锚定自适应横幅广告尺寸 API。Google Mobile Ads SDK 可以使用新的大型锚定自适应横幅广告尺寸 API 向横幅广告投放视频广告需求。
下表详细列出了已弃用的尺寸调整 API 及其替代 API:
| v12(已弃用) | v13(替换) |
|---|---|
GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(CGFloat width) |
GADLargeAnchoredAdaptiveBannerAdSizeWithWidth(CGFloat width) |
GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(CGFloat width) |
GADLargeLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(CGFloat width) |
GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(CGFloat width) |
GADLargePortraitAnchoredAdaptiveBannerAdSizeWithWidth(CGFloat width) |
持续提供 Swift 6 并发支持
13.0.0 版继续添加对 Swift 6 严格并发的支持。
为 neighboringContentURLStrings 数组添加了更严格的类型强制执行
从 13.0.0 版开始,如果在 neighboringContentURLStrings 数组中检测到非 String 类型的对象,Google Mobile Ads SDK 会引发异常。
从 v11 迁移到 v12
升级到 Xcode 16.0
支持的最低 Xcode 版本已提高到 16.0。
Swift 命名支持
12.0.0 版进行了一些更改,以遵循 Swift API 设计准则中的命名规范。这些变更仅影响 Swift。尚未对 Objective-C API 的命名进行任何更改。
类前缀变更
对类前缀进行了以下更改:
- 移除了所有类型的名称中的
GAD前缀。 - 将
GAM前缀重命名为AdManager。 - 将
GADM前缀重命名为Mediation。
解决错误
要解决这些更改导致的错误,最好的方法是进行 Fix-It 修正。
解决命名冲突
如需解决命名冲突,请使用模块提供的命名空间。例如,GADRequest 现在称为 Request。以下示例将 Request 类命名空间化为 Google Mobile Ads SDK:
import GoogleMobileAds
...
var request: GoogleMobileAds.Request?
Swift 变更的详细列表
下表列出了对 Swift API 所做的更改:
| 版本 11 | 版本 12 |
|---|---|
GADAdapterInitializationState |
AdapterInitializationState |
GADAdChoicesPosition |
AdChoicesPosition |
GADAdChoicesView |
AdChoicesView |
GADAdFormat |
AdFormat |
GADAdLoader |
AdLoader |
GADAdLoaderAdType |
AdLoaderAdType |
GADAdLoaderDelegate |
AdLoaderDelegate |
GADAdMetadataDelegate |
AdMetadataDelegate |
GADAdMetadataProvider |
AdMetadataProvider |
GADAdNetworkExtras |
AdNetworkExtras |
GADAdNetworkResponseInfo |
AdNetworkResponseInfo |
GADAdReward |
AdReward |
GADAdSize |
AdSize |
GADAdSizeDelegate |
AdSizeDelegate |
GADAdValue |
AdValue |
GADAdValuePrecision |
AdValuePrecision |
GADAppEventDelegate |
AppEventDelegate |
GADAppOpenAd |
AppOpenAd |
GADAppOpenSignalRequest |
AppOpenSignalRequest |
GADAudioVideoManager |
AudioVideoManager |
GADAudioVideoManagerDelegate |
AudioVideoManagerDelegate |
GADBannerSignalRequest |
BannerSignalRequest |
GADBannerView |
BannerView |
GADBannerViewDelegate |
BannerViewDelegate |
GADCustomEventExtras |
CustomEventExtras |
GADCustomEventRequest |
CustomEventRequest |
GADCustomNativeAd |
CustomNativeAd |
GADCustomNativeAdLoaderDelegate |
CustomNativeAdLoaderDelegate |
GADCustomNativeAdDelegate |
CustomNativeAdDelegate |
GADDebugOptionsViewControllerDelegate |
DebugOptionsViewControllerDelegate |
GADDebugOptionsViewController |
DebugOptionsViewController |
GADDisplayAdMeasurement |
DisplayAdMeasurement |
GADExtras |
Extras |
GADFullScreenPresentingAd |
FullScreenPresentingAd |
GADFullScreenContentDelegate |
FullScreenContentDelegate |
GADAdapterStatus |
AdapterStatus |
GADInitializationStatus |
InitializationStatus |
GADInterstitialAd |
InterstitialAd |
GADInterstitialSignalRequest |
InterstitialSignalRequest |
GADMediaAspectRatio |
MediaAspectRatio |
GADMediaContent |
MediaContent |
GADMediaView |
MediaView |
GADMobileAds |
MobileAds |
GADMultipleAdsAdLoaderOptions |
MultipleAdsAdLoaderOptions |
GADMuteThisAdReason |
MuteThisAdReason |
GADNativeAd |
NativeAd |
GADNativeAdLoaderDelegate |
NativeAdLoaderDelegate |
GADNativeAdView |
NativeAdView |
GADNativeAdCustomClickGestureOptions |
NativeAdCustomClickGestureOptions |
GADNativeAdDelegate |
NativeAdDelegate |
GADNativeAdImage |
NativeAdImage |
GADNativeAdImageAdLoaderOptions |
NativeAdImageAdLoaderOptions |
GADNativeAdInlineBehavior |
NativeAdInlineBehavior |
GADNativeAdInlineBehaviorOptions |
NativeAdInlineBehaviorOptions |
GADNativeAdMediaAdLoaderOptions |
NativeAdMediaAdLoaderOptions |
GADNativeAdUnconfirmedClickDelegate |
NativeAdUnconfirmedClickDelegate |
GADNativeAdViewAdOptions |
NativeAdViewAdOptions |
GADNativeMuteThisAdLoaderOptions |
NativeMuteThisAdLoaderOptions |
GADNativeSignalRequest |
NativeSignalRequest |
GADPresentationError |
PresentationError |
GADPublisherPrivacyPersonalizationState |
PublisherPrivacyPersonalizationState |
GADQueryInfo |
QueryInfo |
GADRequest |
Request |
GADRequestError |
RequestError |
GADRequestConfiguration |
RequestConfiguration |
GADResponseInfo |
ResponseInfo |
GADRewardedAd |
RewardedAd |
GADRewardedSignalRequest |
RewardedSignalRequest |
GADRewardedInterstitialAd |
RewardedInterstitialAd |
GADRewardedInterstitialSignalRequest |
RewardedInterstitialSignalRequest |
GADSearchBannerView |
SearchBannerView |
GADServerSideVerificationOptions |
ServerSideVerificationOptions |
GADSignal |
Signal |
GADSignalRequest |
SignalRequest |
GADVersionNumber |
VersionNumber |
GADVideoController |
VideoController |
GADVideoControllerDelegate |
VideoControllerDelegate |
| Ad Manager | |
GAMBannerAdLoaderDelegate |
AdManagerBannerAdLoaderDelegate |
GAMBannerView |
AdManagerBannerView |
GAMBannerViewOptions |
AdManagerBannerViewOptions |
GAMInterstitialAd |
AdManagerInterstitialAd |
GAMRequest |
AdManagerRequest |
| 中介 | |
GADMAdNetworkAdapter |
MediationAdNetworkAdapter |
GADMAdNetworkConnector |
MediationAdNetworkConnector |
GADMBannerAnimationType |
MediationBannerAnimationType |
GADMediatedUnifiedNativeAd |
MediationUnifiedNativeAd |
GADMediatedUnifiedNativeAdNotificationSource |
MediationUnifiedNativeAdNotificationSource |
GADMediationAd |
MediationAd |
GADMediationAdConfiguration |
MediationAdConfiguration |
GADMediationAdEventDelegate |
MediationAdEventDelegate |
GADMediationAdRequest |
MediationAdRequest |
GADMediationAdapter |
MediationAdapter |
GADMediationAppOpenAd |
MediationAppOpenAd |
GADMediationAppOpenAdEventDelegate |
MediationAppOpenAdEventDelegate |
GADMediationBannerAd |
MediationBannerAd |
GADMediationBannerAdConfiguration |
MediationBannerAdConfiguration |
GADMediationBannerAdEventDelegate |
MediationBannerAdEventDelegate |
GADMediationCredentials |
MediationCredentials |
GADMediationInterstitialAd |
MediationInterstitialAd |
GADMediationInterstitialAdConfiguration |
MediationInterstitialAdConfiguration |
GADMediationInterstitialAdEventDelegate |
MediationInterstitialAdEventDelegate |
GADMediationNativeAd |
MediationNativeAd |
GADMediationNativeAdConfiguration |
MediationNativeAdConfiguration |
GADMediationNativeAdEventDelegate |
MediationNativeAdEventDelegate |
GADMediationRewardedAd |
MediationRewardedAd |
GADMediationRewardedAdConfiguration |
MediationRewardedAdConfiguration |
GADMediationRewardedAdEventDelegate |
MediationRewardedAdEventDelegate |
GADMediationServerConfiguration |
MediationServerConfiguration |
| 实时出价 | |
GADRTBAdapter |
RTBAdapter |
GADRTBMediationSignalsConfiguration |
RTBMediationSignalsConfiguration |
GADRTBRequestParameters |
RTBRequestParameters |
常量
| 版本 11 | 版本 12 |
|---|---|
GADAdLoaderAdType.gamBanner |
AdLoaderAdType.adManagerBanner |
GADAdSizeBanner |
AdSizeBanner |
GADAdSizeFluid |
AdSizeFluid |
GADAdSizeFullBanner |
AdSizeFullBanner |
GADAdSizeInvalid |
AdSizeInvalid |
GADAdSizeLargeBanner |
AdSizeLargeBanner |
GADAdSizeLeaderboard |
AdSizeLeaderboard |
GADAdSizeMediumRectangle |
AdSizeMediumRectangle |
GADAdSizeSkyscraper |
AdSizeSkyscraper |
GoogleMobileAdsVersionString |
GoogleMobileAdsVersion |
属性
| 类型 | 版本 11 | 版本 12 |
|---|---|---|
| GADAdLoader | loading |
isLoading |
| GADAudioVideoManager | audioSessionApplicationManaged |
isAudioSessionApplicationManaged |
| GADBannerView | autoloadEnabled |
isAutoloadEnabled |
| GADMobileAds | sharedInstance |
shared |
applicationMuted |
isApplicationMuted |
|
| GADMuteThisAdReason | reasonDescription |
reason |
| GADNativeAd | customMuteThisAdAvailable |
isCustomMuteThisAdAvailable |
| GADNativeAdCustomClickGestureOptions | tapsAllowed |
areTapsAllowed |
| GADNativeAdImageAdLoaderOptions | imageLoadingDisabled |
isImageLoadingDisabled |
| GADNativeMuteThisAdLoaderOptions | customMuteThisAdRequested |
isCustomMuteThisAdRequested |
| GADNativeSignalRequest | imageLoadingDisabled |
isImageLoadingDisabled |
customMuteThisAdRequested |
isCustomMuteThisAdRequested |
|
| GADRequest | neighboringContentURLStrings |
neighboringContentURLs |
| GADResponseInfo | extrasDictionary |
extras |
| GADServerSideVerificationOptions | customRewardString |
customRewardText |
| GADSignal | signalString |
signal |
| GADSignalRequest | neighboringContentURLStrings |
neighboringContentURLs |
| GADVideoController | customControlsRequested |
areCustomControlsRequested |
clickToExpandEnabled |
isClickToExpandEnabled |
|
| GADVideoOptions | startMuted |
shouldStartMuted |
customControlsRequested |
areCustomControlsRequested |
|
clickToExpandRequested |
isClickToExpandRequested |
函数
| 类型 | 版本 11 | 版本 12 |
|---|---|---|
| GADAdSize | GADPortraitInlineAdaptiveBannerAdSizeWithWidth(_:) |
portraitInlineAdaptiveBanner(width:) |
GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(_:) |
landscapeInlineAdaptiveBanner(width:) |
|
GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(_:) |
currentOrientationInlineAdaptiveBanner(width:) |
|
GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(_:, _:) |
inlineAdaptiveBanner(width:maxHeight:) |
|
GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(_:) |
portraitAnchoredAdaptiveBanner(width:) |
|
GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(_:) |
landscapeAnchoredAdaptiveBanner(width:) |
|
GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(_:) |
currentOrientationAnchoredAdaptiveBanner(width:) |
|
GADAdSizeFromCGSize(_:) |
adSizeFor(cgSize:) |
|
GADAdSizeFullWidthPortraitWithHeight(_:) |
fullWidthPortrait(height:) |
|
GADAdSizeFullWidthLandscapeWithHeight(_:) |
fullWidthLandscape(height:) |
|
GADAdSizeEqualToSize(_:, _:) |
isAdSizeEqualToSize(size1:size2:) |
|
IsGADAdSizeValid(_:) |
isAdSizeValid(size:) |
|
GADAdSizeIsFluid(_:) |
isAdSizeFluid(size:) |
|
CGSizeFromGADAdSize(_:) |
cgSize(for:) |
|
NSStringFromGADAdSize(_:) |
string(for:) |
|
NSValueFromGADAdSize(_:) |
nsValue(for:) |
|
GADAdSizeFromNSValue(_:) |
adSizeFor(nsValue:) |
|
GADClosestValidSizeForAdSizes(_:_:) |
closestValidSizeForAdSizes(original:possibleAdSizes:) |
|
| GADAppEventDelegate | adView(_:didReceiveAppEvent:withInfo:) |
adView(_:didReceiveAppEvent:with:) |
interstitialAd(_:didReceiveAppEvent:withInfo:) |
adView(_:didReceiveAppEvent:with:) |
|
| GADAppOpenAd | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:) |
present(from:) |
|
| GADBannerView | load(withAdResponseString:) |
load(with:) |
| GADInterstitial | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:) |
present(from:) |
|
| GADRewardedAd | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:userDidEarnRewardHandler:) |
present(from:userDidEarnRewardHandler:) |
|
| GADRewardedInterstitialAd | load(withAdResponseString:) |
load(with:) |
load(withAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
|
canPresent(fromRootViewController:) |
canPresent(from:) |
|
present(fromRootViewController:userDidEarnRewardHandler:) |
present(from:userDidEarnRewardHandler:) |
|
| GADVersionNumber | GADGetStringFromVersionNumber(_ version: GADVersionNumber) |
string(for:) |
| 中介 | ||
| GADMAdNetworkAdapter | getBannerWith(_:) |
getBanner(with:) |
presentInterstitial(fromRootViewController:) |
presentInterstitial(from:) |
|
getNativeAd(withAdTypes:options:) |
getNativeAd(with:options:) |
|
| GADMediatedUnifiedNativeAd | didRecordClickOnAsset(withName:view:viewController:) |
didRecordClickOnAsset(with:view:viewController:) |
| GADMediationAdapter | setUpWith(_:completionHandler:) |
setUp(with:completionHandler:) |
| GADMediationAdSize | present(fromRootViewController:) |
present(from:) |
| GADMediationAppOpenAd | present(fromRootViewController:) |
present(from:) |
| GADMediationInterstitialAd | present(fromRootViewController:) |
present(from:) |
| GADMediationRewardedAd | present(fromRootViewController:) |
present(from:) |
| GAMInterstitialAd | load(withAdManagerAdUnitID:request:completionHandler:) |
load(with:request:completionHandler:) |
设置自定义定位参数
如需在广告请求中设置自定义定位,请使用 customTargeting。
控制视频静音状态的 API 变更
GADVideoController 上的 isMuted 属性和 setMute: 方法已替换为 muted 属性。
内嵌自适应广告的变化
为了优化空间利用率,内嵌自适应广告最初不会占用框架中的任何空间。现在,在 Google 移动广告 SDK 返回广告之前,使用内嵌自适应广告尺寸调用 CGSizeFromGADAdSize(_:) 会返回 0 高度。
移除了自定义搜索广告
以下类已移除且无替代项:
GADDynamicHeightSearchBannerViewGADDynamicHeightSearchRequestGADSearchBannerView
错误代码变更
以下错误代码已更改:
| 类 | 备注 |
|---|---|
GADErrorMediationNoFill |
现在,错误会以 GADErrorNoFill 形式返回。 |
GADErrorReceivedInvalidResponse |
已被 GADErrorReceivedInvalidAdString 替换。 |
移除了 GADSimulatorID
移除了 GADSimulatorID。默认情况下,模拟器已处于测试模式。
自定义定位变更
GADRequest 上的 customTargeting 字典现在使用 Any(而非 String)作为值类型。这样,您就可以向 API 传递数值。
对 extra 参数的更改
- 将键传入
additionalParameters不再会将自定义定位条件应用于 Ad Manager 广告请求。如需应用自定义定位,请参阅自定义定位。
- 不再支持将
max_ad_content_rating键传入additionalParameters。如需设置广告内容分级上限,请参阅广告内容过滤。
从 v10 迁移到 v11
最低部署目标
最低部署目标版本已提高到 iOS 12。
最低 Xcode 版本
支持的最低 Xcode 版本已提高到 15.1。
广告停止在 iOS 12 设备上投放
Google Mobile Ads SDK 版本 11.0.0 仅在搭载 iOS 13 及更高版本的设备上投放广告。
移除了 GoogleAppMeasurement 依赖项
在 11.0.0 版中,对 GoogleAppMeasurement 的依赖项已被移除。此依赖项在 AdMob 中为用户指标切换开关提供支持,将于 2024 年初停用。如需继续在 AdMob 中收集用户指标,请将 AdMob 应用与 Firebase 相关联,并将 Google Analytics for Firebase SDK 集成到您的应用中。
全屏广告展示方式的变化
以下变更会影响各种广告格式:
- 应用启动
- 插页式广告
- 已获得奖励
- 插页式激励广告
-canPresentFromRootViewController:error: 和 -presentFromRootViewController: 中的视图控制器参数可以为 null。如果传递 nil,则广告会从视图控制器层次结构中最顶层的视图控制器中展示。
已移除的方法
移除了以下方法。
| v11.0.0 中的类型 | 方法 | 备注 |
|---|---|---|
| GADAppOpenAd | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) |
请改用 load(withAdUnitID adUnitID: String, request: GADRequest?)。 |
| GADMediationBannerAdEventDelegate | willBackgroundApplication() |
无替代项。 |
| GADMediationInterstitialAdEventDelegate | willBackgroundApplication() |
无替代项。 |
| GADMediationNativeAdEventDelegate | willBackgroundApplication() |
无替代项。 |
| GADMediationRewardedAdEventDelegate | didRewardUser(with reward: GADAdReward) |
请改用 didRewardUser()。 |
| GADMediatedUnifiedNativeAdNotificationSource | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) |
无替代项。 |
| GADRequestConfiguration | setSameAppKeyEnabled(_ enabled: Bool) |
请改用 setPublisherFirstPartyIDEnabled(_ enabled: Bool)。 |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) |
请改用 tagForUnderAgeOfConsent 属性。 |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
请改用 tagForChildDirectedTreatment 属性。 |
已移除的属性
以下属性已移除。
| v11.0.0 中的类 | 属性 | 备注 |
|---|---|---|
| GADMediationAdConfiguration | hasUserLocation | 无替代项。 |
| userLatitude | ||
| userLongitude | ||
| userLocationAccuracyInMeters | ||
| childDirectedTreatment | 请改用 GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment。 |
|
| GADResponseInfo | adNetworkClassName | 请改用 loadedAdNetworkResponseInfo 中的 adNetworkClassName。 |
移除了 GADAdFormatUnknown
移除了 GADAdFormatUnknown,且未提供任何替换项。
日志记录 SDK 版本的变更
版本 11.0.0 移除了 sdkVersion。如需记录 Google Mobile Ads SDK 版本,请改用 versionNumber。
版本 10.0.0
GADMobileAds.sharedInstance().sdkVersion
版本 11.0.0
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
GADAdLoader 错误处理方式变更
从 11.0.0 版开始,如果 GADAdLoader 的 delegate 不符合请求的广告类型的委托协议,则不会发出广告请求。之前,它在发出广告请求后失败。
测试行为的变化
请参阅下表,其中显示了以下属性返回 true 的更新条件。
| 类 | 属性 |
|---|---|
| GADMediationAdConfiguration | isTestRequest |
| GADCustomEventRequest | isTesting |
| v10.0.0 | v11.0.0 |
|
|
从 v9 迁移到 v10
广告停止在 iOS 11 设备上投放
Google Mobile Ads SDK 版本 10.0.0 仅在搭载 iOS 12 及更高版本的设备上投放广告。
升级到 Google Mobile Ads SDK 版本 10.0.0 不会影响您的应用在 iOS 11 和 iOS 10 设备上的行为,但广告不会在这些设备上投放。
需要 Ad Manager 应用 ID
现在,所有 Ad Manager 应用的 Info.plist 中都需要 Ad Manager 应用 ID,并且该 ID 需要采用 ca-app-pub-################~########## 格式。如需了解更多详情,请参阅更新您的 Info.plist。
需要 GoogleAppMeasurement.xcframework
现在,所有 Ad Manager 应用都需要 GoogleAppMeasurement.xcframework。如果您通过 CocoaPods 或 Swift Package Manager 安装 Google Mobile Ads SDK,则无需执行任何其他操作。如果您手动安装框架,请参阅手动下载,了解更多详情。
不再支持使用位码构建
现在,您必须在移动应用中停用位码,才能集成 Google Mobile Ads SDK。
已移除的类型
| 类型 | 备注 |
|---|---|
| GADGender | 无替代项。 |
| GADMRewardBasedVideoAdNetworkAdapterProtocol | 选择广告联盟一文中列出的所有激励广告中介适配器已停止使用这些协议超过一年了。 将 GADMediationAdapter 用于中介和自定义事件。 |
| GADMRewardBasedVideoAdNetworkConnectorProtocol |
已移除的属性
以下属性已移除且无替代项。
| v10.0.0 中的类 | 属性 |
|---|---|
| GADMediationAdRequest | userBirthday |
| userGender | |
| userHasLocation | |
| userLatitude | |
| userLongitude | |
| userLocationAccuracyInMeters | |
| userLocationDescription | |
| GADCustomEventRequest | userHasLocation |
| userLatitude | |
| userLongitude | |
| userLocationAccuracyInMeters | |
| userLocationDescription |
从 v8 迁移到 v9
广告停止在 iOS 10 设备上投放
Google Mobile Ads SDK 版本 9.0.0 支持的最低 iOS 版本为 iOS 11。
升级到 Google Mobile Ads SDK 版本 9.0.0 不会影响您的应用在 iOS 10 设备上的行为,但广告不会在这些设备上投放。
状态栏控制规定的执行更严格
从版本 9.0.0 开始,当您展示全屏格式的广告时,您的应用应确保广告能够控制状态栏的显示。如果您未能这样做,将会在日志中看到一条出错提示。
根据应用中视图控制器的具体布局,您可能无需做出任何更改即可确保实现这一点。考虑您是否需要在广告的 rootViewController 上设置 childViewControllerForStatusBarHidden 属性。
将 adDidPresentFullScreenContent: 重命名为 adWillPresentFullScreenContent:
这不会带来任何行为上的变化。委托方法在广告即将展示之前调用,因此新的方法名称可以更好地体现其功能。
移除了 GADRequest 上的 Location Setting API
- (void)setLocationWithLatitude:longitude:accuracy: 已从 GADRequest 中删除,因为 Google 不使用位置数据来定位广告。如果需要,可以使用第三方 API 向第三方广告联盟提供该信息。
弃用了自定义事件接口
借助自定义事件,使用 Ad Manager 中介的发布商可以为支持的广告联盟以外的广告联盟添加广告瀑布流中介。
弃用了所有自定义事件协议。改为使用现有的 GADMediationAdapter 和 GADMediationAdEventDelegate 协议来实现相同的功能。这项变更让机制更清晰明了,并让您可为之前不可用的激励广告和插页式滚显广告创建自定义事件。
API
下表列出了从版本 9.0.0 开始应使用的 Custom Events API 所对应的 Mediation Adapter API。
| v8 | v9 | |
|---|---|---|
| GADCustomEventBanner GADCustomEventInterstitial GADCustomEventNativeAd |
GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediationRewardedAd GADMediationNativeAd |
delegate
|
委托由 GADMediationAdapter 类的每个加载函数的加载完成处理程序返回
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
| 不适用 | -loadInterscrollerAdFor |
|
| 不适用 | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
|
代理方法
下表列出了从版本 9.0.0 开始应使用的自定义事件委托方法所对应的中介广告事件委托方法。
| v8 | v9 | |
|---|---|---|
| GADCustomEventBannerDelegate GADCustomEventInterstitialDelegate GADCustomEventNativeAdDelegate |
GADMediationAdEventDelegate | GADMediationAd |
-customEventBanner:didReceiveAd:-customEventInterstitialDidReceiveAd:
|
广告加载状态包含在 GADMediationAdapter 类中每个加载函数的加载完成处理程序中
|
|
-customEventBanner:didFailAd:-customEventInterstitial:didFailAd:
|
||
-customEventBannerWasClicked:-customEventInterstitialWasClicked:
|
-reportClick |
|
-customEventBannerWill-customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill-customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid-customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill-customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
|
其他已移除/替换的方法和常量
| 方法、常量或属性的变更 | |
|---|---|
带 kGAD- 前缀的常量
|
已移除。使用带 GAD- 前缀的常量。
|
GADAdNetworkResponseInfo
|
移除了 credentials。请改用 adUnitMapping。
|
GAMRequest
|
弃用了 GAMRequest 中的 kGAMSimulatorID。
改用 GADRequestConfiguration 中的 GADSimulatorID。
|
GADCustomNativeAd
|
弃用了 GADCustomNativeAd 中的 mediaView。
请改用 mediaContent。
|
GoogleMobileAds 中的应用内购买 API |
移除了 GoogleMobileAds 中的 inAppPurchase API。
|
从 v7 迁移到 v8
Google Mobile Ads SDK 版本 8.0.0 引入了一些重大变更,并重命名和移除了一些 API。
关于全屏广告格式 API 的更新
从版本 8.0.0 开始,插页式广告和激励广告采用通用的全屏广告样式,以提高一致性。这些新的全屏广告 API 与版本 7 全屏广告 API 有两个主要区别:
静态类方法
load。之前加载/展示全屏广告的方法如下:
- 创建广告对象实例并保留对它的引用。
- 分配一个用于处理加载和展示回调的委托。
- 加载广告。
- 使用
isReady检查广告是否已加载。 - 展示广告。
在第 8 版中,方法略有变化。加载回调不再是委托的一部分。而是作为完成处理程序传递到
load方法中:- 在广告类上调用静态加载方法,并提供加载完成处理程序。
- 在加载完成回调中,保留对返回的已加载广告的引用。
- 分配一个用于处理展示回调的委托。
- 展示广告。
新方法具有以下优势:
- 您永远不会引用未加载的广告。
- 您无需在广告加载期间保留广告对象。
一致的广告事件。
事件类型 现有 API v8 API 加载事件 GADInterstitialDelegate或GADRewardedAdDelegateGAMInterstitialAdLoadCompletionHandler或GADRewardedAdLoadCompletionHandler演示文稿事件 GADFullScreenContentDelegate之前,如需监听任何广告事件,您需要将实现
GADInterstitialDelegate协议的类注册到插页式广告的委托属性,或将实现GADRewardedAdDelegate协议的类注册到激励广告的委托属性,具体取决于您使用的格式。此委托具有与广告的加载和展示生命周期相关的方法。在第 8 版中,加载和展示事件是分开的。现在,您可以在展示广告之前的任何时间注册
GADFullScreenContentDelegate,而无需在加载广告之前设置单个委托。广告加载事件(因格式而异)会移至在加载方法中传递的单个加载完成处理程序。
插页式广告
加载广告
以下代码段展示了如何加载插页式广告,以及如何监听广告加载成功或失败时的事件。
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: DFPInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial") interstitial.delegate = self let request = GAMRequest() interstitial.load(request) } /// Tells the delegate an ad request succeeded. func interstitialDidReceiveAd(_ ad: DFPInterstitial) { print("Interstitial ad loaded.") } /// Tells the delegate an ad request failed. func interstitial(_ ad: DFPInterstitial, didFailToReceiveAdWithError error: GADRequestError) { print("Interstitial ad failed to load with error: \(error.localizedDescription)") } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) DFPInterstitial *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:@"/21775744923/example/interstitial"]; self.interstitial.delegate = self; GAMRequest *request = [GAMRequest request]; [self.interstitial loadRequest:request]; } /// Tells the delegate an ad request succeeded. - (void)interstitialDidReceiveAd:(DFPInterstitial *)ad { NSLog(@"Insterstitial ad loaded."); } /// Tells the delegate an ad request failed. - (void)interstitial:(DFPInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"Interstitial ad failed to load with error: %@", [error localizedDescription]); }
v8
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADFullScreenContentDelegate { var interstitial: GAMInterstitialAd? override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GAMInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738", request: request, completionHandler: { (ad, error) in if let error = error { print("Failed to load interstitial ad with error: \(error.localizedDescription)") return } self.interstitial = ad self.interstitial.fullScreenContentDelegate = self } ) } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GAMInterstitialAd *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial" request:request completionHandler:^(GAMInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]); return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; }
展示广告
v7
Swift
func showInterstitial() { ... if interstitial.isReady { interstitial.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showInterstitial: { ... if (self.interstitial.isReady) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
v8
Swift
func showInterstitial() { ... if let ad = interstitial { ad.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showInterstitial: { ... if (self.interstitial) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
展示广告事件
以下代码段展示了如何处理广告展示(成功或失败)以及广告关闭时的回调。
v7
Swift
override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial") interstitial.delegate = self ... } /// Tells the delegate that an interstitial will be presented. func interstitialWillPresentScreen(_ ad: DFPInterstitial) { print("Interstitial ad will be presented.") } /// Tells the delegate the interstitial is to be animated off the screen. func interstitialWillDismissScreen(_ ad: DFPInterstitial) { print("Interstitial ad will be dismissed.") } /// Tells the delegate the interstitial had been animated off the screen. func interstitialDidDismissScreen(_ ad: DFPInterstitial) { print("Interstitial ad dismissed.") } /// Tells the delegate that a user click will open another app /// (such as the App Store), backgrounding the current app. /// /// This is not a reliable callback for an ad click event and is removed in /// version 8. If you wish to listen to an ad causing a user to leave the app, /// use applicationWillResignActive: or sceneWillResignActive: instead. func interstitialWillLeaveApplication(_ ad: DFPInterstitial) { print("Interstitial ad will leave application.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:"/21775744923/example/interstitial"]; self.interstitial.delegate = self; ... } /// Tells the delegate that an interstitial will be presented. - (void)interstitialWillPresentScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will be presented."); } /// Tells the delegate the interstitial is to be animated off the screen. - (void)interstitialWillDismissScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will be dismissed."); } /// Tells the delegate the interstitial had been animated off the screen. - (void)interstitialDidDismissScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad dismissed."); } /// Tells the delegate that a user click will open another app /// (such as the App Store), backgrounding the current app. /// /// This is not a reliable callback for an ad click event and is removed in /// version 8. If you wish to listen to an ad causing a user to leave the app, /// use applicationWillResignActive: or sceneWillResignActive: instead. - (void)interstitialWillLeaveApplication:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will leave application."); }
v8
Swift
override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GAMInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738", request: request, completionHandler: { (ad, error) in if let error = error { print(error.localizedDescription) return } self.interstitial = ad self.interstitial.fullScreenContentDelegate = self } ) } func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Ad did present full screen content.") } func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) { print("Ad failed to present full screen content with error \(error.localizedDescription).") } func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Ad did dismiss full screen content.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial" request:request completionHandler:^(GAMInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]) return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; } - (void)adDidPresentFullScreenContent:(id)ad { NSLog(@"Ad did present full screen content."); } - (void)ad:(id )ad didFailToPresentFullScreenContentWithError:(NSError *)error { NSLog(@"Ad failed to present full screen content with error %@.", [error localizedDescription]); } - (void)adDidDismissFullScreenContent:(id )ad { NSLog(@"Ad did dismiss full screen content."); }
已获得奖励
加载广告
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADRewardedAdDelegate { /// The rewarded ad. var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd.delegate = self rewardedAd?.load(GAMRequest()) { error in if let error = error { print("Rewarded ad failed to load with error: \(error.localizedDescription)") } else { print("Rewarded ad loaded.") } } } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.rewardedAd = [[GADRewardedAd alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"]; self.rewardedAd.delegate = self; GAMRequest *request = [GAMRequest request]; [self.rewardedAd loadRequest:request completionHandler:^(GADRequestError * _Nullable error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); } else { NSLog(@"Rewarded ad loaded."); } }]; }
v8
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADFullScreenContentDelegate { /// The rewarded ad. var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136", request: request, completionHandler: { (ad, error) in if let error = error { print("Rewarded ad failed to load with error: \(error.localizedDescription)") return } self.rewardedAd = ad self.rewardedAd?.fullScreenContentDelegate = self } ) } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; NSLog(@"Rewarded ad loaded."); self.rewardedAd.fullScreenContentDelegate = self; }
展示广告并处理奖励
对于激励广告,您需要处理用户获得奖励时的事件。借助 GADRewardedAd API 的第 7 版,您可以将 rewardedAd:userDidEarnReward: 作为 GADRewardedAdDelegate 协议的一部分来实现。对于版本 8,您需要实现 GADUserDidEarnRewardHandler 才能展示广告。
v7
Swift
func showRewardedAd() { ... if rewardedAd.isReady { rewardedAd.present(fromRootViewController: self delegate:self) } else { print("Ad wasn't ready") } } /// Tells the delegate that the user earned a reward. func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarnReward: GADAdReward) { // TODO: Reward the user. }
Objective-C
- (void)showRewardedAd: { ... if (self.rewardedAd.isReady) { [self.rewardedAd presentFromRootViewController:self delegate:self]; } else { NSLog(@"Ad wasn't ready"); } } /// Tells the delegate that the user earned a reward. - (void)rewardedAd:(GADRewardedAd *)rewardedAd userDidEarnReward:(GADAdReward *)reward { // TODO: Reward the user. }
v8
Swift
func showRewardedAd() { ... if let ad = rewardedAd { ad.present(fromRootViewController: self, userDidEarnRewardHandler: { let reward = ad.adReward // TODO: Reward the user. } ) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showRewardedAd: { ... if (self.rewardedAd) { [self.rewardedAd presentFromRootViewController:self userDidEarnRewardHandler:^ { GADAdReward *reward = self.rewardedAd.adReward; // TODO: Reward the user. }]; } else { NSLog(@"Ad wasn't ready"); } }
展示广告事件
使用 GADRewardedAd API 时,您需要将 GADRewardedAdDelegate 传递给展示广告的方法。借助 GADRewardedAd API,您可以在展示广告之前将 GADFullscreenContentDelegate 设置为广告的属性。
v7
Swift
func showRewardedAd() { ... if rewardedAd.isReady { rewardedAd.present(fromRootViewController: self delegate:self) } else { print("Ad wasn't ready") } } /// Tells the delegate that the rewarded ad was presented. func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) { print("Rewarded ad failed to present with error: \(error.localizedDescription).") }
Objective-C
- (void)showRewardedAd: { ... if (self.rewardedAd.isReady) { [self.rewardedAd presentFromRootViewController:self delegate:self]; } else { NSLog(@"Ad wasn't ready"); } } /// Tells the delegate that the rewarded ad was presented. - (void)rewardedAdDidPresent:(GADRewardedAd *)rewardedAd { NSLog(@"Rewarded ad presented."); } /// Tells the delegate that the rewarded ad failed to present. - (void)rewardedAd:(GADRewardedAd *)rewardedAd didFailToPresentWithError:(NSError *)error { NSLog(@"Rewarded ad failed to present with error: %@", [error localizedDescription]); } /// Tells the delegate that the rewarded ad was dismissed. - (void)rewardedAdDidDismiss:(GADRewardedAd *)rewardedAd { NSLog(@"Rewarded ad dismissed."); }
v8
Swift
override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136", request: request, completionHandler: { (ad, error) in if let error = error { print(error.localizedDescription) return } self.rewardedAd = ad self.rewardedAd?.fullScreenContentDelegate = self } ) } /// Tells the delegate that the rewarded ad was presented. func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) { print("Rewarded ad failed to present with error: \(error.localizedDescription).") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; NSLog(@"Rewarded ad loaded."); self.rewardedAd.fullScreenContentDelegate = self; } /// Tells the delegate that the rewarded ad was presented. - (void)adDidPresentFullScreenContent:(id)ad { NSLog(@"Rewarded ad presented."); } /// Tells the delegate that the rewarded ad failed to present. - (void)ad:(id )ad didFailToPresentFullScreenContentWithError:(NSError *)error { NSLog(@"Rewarded ad failed to present with error: %@", [error localizedDescription]); } /// Tells the delegate that the rewarded ad was dismissed. - (void)adDidDismissFullScreenContent:(id )ad { NSLog(@"Rewarded ad dismissed."); }
移除了旧版 GADRewardedBasedVideoAd API
较新版本的 GADRewardedAd API 于 2019 年 3 月首次推出,在之后超过 18 个月的时间里一直是首选激励广告 API。与旧版 GADRewardedBasedVideoAd API 相比,新版 API 具备更多增强功能,其中包括一次加载多个激励广告的功能。
旧版 GADRewardedBasedVideoAd API 已在 SDK 8.0.0 版中移除。
弃用智能横幅广告,改用自适应横幅广告
弃用了智能横幅广告,现在使用的是自适应横幅广告。自适应横幅广告的效果更好,可以让您更灵活地设置广告宽度。如果您希望继续使用全宽横幅广告,仍然可以使用自适应横幅广告来实现,如以下代码段所示:
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 中已更改或已移除的特定类名称。总结:
- 与
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 |
| GADInAppPurchase | 已移除 |
| GADInterstitial | GADInterstitialAd |
| GADNativeExpressAdView | 已移除 |
| GADRewardBasedVideoAd | 已移除 |
| GADInstreamAd | 已移除 |
| GADInstreamAdView | 已移除 |
移除/替换的方法
下表列出了版本 8 中的具体更改。总结:
- 移除了之前已废弃的方法和属性。
- 移除了所有格式的
-willLeaveApplication:委托方法。 - 广告联盟类名称已移至
GADResponseInfo属性。 - 测试设备标识符已移至
GADRequestConfiguration属性。
| v7.68.0 中的类 | v7.68.0 API | v8.0.0 API | 备注 |
|---|---|---|---|
| GADMobileAds | +configureWithApplicationID: | -startWithCompletionHandler: | 现在,应用 ID 已在 Info.plist 中设置。 |
| +disableAutomatedInApp |
-disableAutomatedInApp |
||
| +disableSDKCrashReporting | -disableSDKCrashReporting | ||
| GADRequest | testDevices | GADRequestConfiguration |
testDeviceIdentifiers 属性适用于所有广告请求,而旧的 testDevices 属性是按请求设置的。 |
| gender | 已移除 | ||
| 生日 | 已移除 | ||
| +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: | -bannerViewWillDismissScreen: | ||
| -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 |