Migrasi SDK

Halaman ini membahas migrasi untuk versi Google Mobile Ads SDK untuk iOS saat ini dan sebelumnya. Versi 12.0.0 diperkirakan akan dirilis pada Februari 2025.

Bermigrasi dari 11 ke v12

Mengupgrade ke Xcode 16.0

Versi Xcode minimum yang didukung telah ditingkatkan menjadi 16.0.

Dukungan penamaan Swift

Versi 12.0.0 menyertakan perubahan untuk mengikuti konvensi penamaan dalam Swift Pedoman Desain API. Perubahan ini hanya memengaruhi Swift. Tidak ada perubahan penamaan yang dilakukan pada Objective-C API.

Perubahan awalan class

Perubahan berikut telah dilakukan pada awalan class:

  • Menghapus awalan GAD di seluruh nama untuk semua jenis.
  • Mengganti nama awalan GAM menjadi AdManager.
  • Mengganti nama awalan GADM menjadi Mediation.

Mengatasi error

Cara terbaik untuk mengatasi error yang dihasilkan dari perubahan ini adalah dengan membuat koreksi Fix-It.

Menyelesaikan konflik penamaan

Untuk mengatasi konflik penamaan, gunakan namespace yang disediakan oleh modul. Misalnya, GADRequest sekarang bernama Request. Contoh namespace berikut adalah class Request Google Mobile Ads SDK:

import GoogleMobileAds
...
var request: GoogleMobileAds.Request?

Daftar mendetail perubahan Swift

Tabel berikut mencantumkan perubahan yang dilakukan pada Swift API:

Versi 11 Versi 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
Mediasi
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
Bidding real-time
GADRTBAdapter RTBAdapter
GADRTBMediationSignalsConfiguration RTBMediationSignalsConfiguration
GADRTBRequestParameters RTBRequestParameters

Konstanta

Versi 11 Versi 12
GADAdLoaderAdType.gamBanner AdLoaderAdType.adManagerBanner
GADAdSizeBanner AdSizeBanner
GADAdSizeFluid AdSizeFluid
GADAdSizeFullBanner AdSizeFullBanner
GADAdSizeInvalid AdSizeInvalid
GADAdSizeLargeBanner AdSizeLargeBanner
GADAdSizeLeaderboard AdSizeLeaderboard
GADAdSizeMediumRectangle AdSizeMediumRectangle
GADAdSizeSkyscraper AdSizeSkyscraper
GoogleMobileAdsVersionString GoogleMobileAdsVersion

Properti

Jenis Versi 11 Versi 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

Fungsi

Jenis Versi 11 Versi 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:)
Mediasi
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:)

Perubahan API untuk mengontrol status bisukan video

Properti isMuted dan metode setMute: di GADVideoController diganti dengan properti muted.

Perubahan pada iklan adaptif inline

Untuk mengoptimalkan penggunaan ruang, iklan adaptif inline awalnya tidak menempati ruang dalam bingkai. Memanggil CGSizeFromGADAdSize(_:) dengan ukuran iklan adaptif inline kini menampilkan tinggi 0 hingga Google Mobile Ads SDK menampilkan iklan.

Iklan penelusuran khusus dihapus

Class berikut dihapus tanpa penggantian:

  • GADDynamicHeightSearchBannerView
  • GADDynamicHeightSearchRequest
  • GADSearchBannerView

Perubahan pada kode error

Kode error berikut telah diubah:

Kelas Catatan
GADErrorMediationNoFill Error kini ditampilkan sebagai GADErrorNoFill.
GADErrorReceivedInvalidResponse Telah diganti dengan GADErrorReceivedInvalidAdString.

Menghapus GADSimulatorID

GADSimulatorID dihapus. Simulator sudah dalam mode pengujian secara default.

Perubahan pada penargetan kustom

Kamus customTargeting di GADRequest kini menggunakan Any, bukan String sebagai jenis nilai. Hal ini memungkinkan Anda meneruskan nilai numerik ke API.

Perubahan pada parameter tambahan

Bermigrasi dari v10 ke v11

Target deployment minimum

Target deployment minimum telah ditingkatkan menjadi iOS 12.

Versi Xcode minimum

Versi Xcode minimum yang didukung telah ditingkatkan menjadi 15.1.

Iklan berhenti ditayangkan di iOS 12

Google Mobile Ads SDK versi 11.0.0 hanya menayangkan iklan di perangkat yang menjalankan iOS 13 dan yang lebih tinggi.

Menghapus dependensi GoogleAppMeasurement

Pada versi 11.0.0, dependensi pada GoogleAppMeasurement telah dihapus. Dependensi ini yang mendukung tombol metrik pengguna di AdMob akan dihentikan pada awal tahun 2024. Untuk terus mengumpulkan metrik pengguna di AdMob, tautkan aplikasi AdMob Anda ke Firebase dan integrasikan Google Analytics for Firebase SDK ke dalam aplikasi Anda.

Perubahan pada presentasi iklan layar penuh

Perubahan berikut memengaruhi berbagai format iklan:

  • Pembukaan aplikasi
  • Interstisial
  • Reward
  • Interstisial reward

Parameter pengontrol tampilan di -canPresentFromRootViewController:error: dan -presentFromRootViewController: bersifat nullable. Jika nil diteruskan, iklan akan ditampilkan dari pengontrol tampilan paling atas dalam hierarki pengontrol tampilan.

Metode dihapus

Metode berikut dihapus.

Jenis v11.0.0 Metode Catatan
GADAppOpenAd load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) Sebagai gantinya, gunakan load(withAdUnitID adUnitID: String, request: GADRequest?).
GADMediationBannerAdEventDelegate willBackgroundApplication() Tidak ada pengganti.
GADMediationInterstitialAdEventDelegate willBackgroundApplication() Tidak ada pengganti.
GADMediationNativeAdEventDelegate willBackgroundApplication() Tidak ada pengganti.
GADMediationRewardedAdEventDelegate didRewardUser(with reward: GADAdReward) Sebagai gantinya, gunakan didRewardUser().
GADMediatedUnifiedNativeAdNotificationSource mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) Tidak ada pengganti.
GADRequestConfiguration setSameAppKeyEnabled(_ enabled: Bool) Sebagai gantinya, gunakan setPublisherFirstPartyIDEnabled(_ enabled: Bool).
tagForUnderAge(ofConsent underAgeOfConsent: Bool) Sebagai gantinya, gunakan properti tagForUnderAgeOfConsent.
tag(forChildDirectedTreatment childDirectedTreatment: Bool) Sebagai gantinya, gunakan properti tagForChildDirectedTreatment.

Properti dihapus

Properti berikut dihapus.

Class v11.0.0 Properti Catatan
GADMediationAdConfiguration hasUserLocation Tidak ada pengganti.
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment Sebagai gantinya, gunakan GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment.
GADResponseInfo adNetworkClassName Sebagai gantinya, gunakan adNetworkClassName dari loadedAdNetworkResponseInfo.

Menghapus GADAdFormatUnknown

Menghapus GADAdFormatUnknown tanpa penggantian.

Perubahan pada versi SDK logging

Versi 11.0.0 menghapus sdkVersion. Untuk mencatat versi Google Mobile Ads SDK ke dalam log, gunakan versionNumber sebagai gantinya.

Versi 10.0.0

GADMobileAds.sharedInstance().sdkVersion

Versi 11.0.0

GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)

Perubahan pada penanganan error GADAdLoader

Mulai versi 11.0.0, GADAdLoader tidak membuat permintaan iklan jika delegate tidak sesuai dengan protokol delegasi jenis iklan yang diminta. Sebelumnya, pengujian ini gagal setelah permintaan iklan dibuat.

Perubahan pada perilaku pengujian

Lihat tabel yang menunjukkan kondisi yang diperbarui saat properti berikut menampilkan true.

Kelas Properti
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • Perangkat dideklarasikan secara eksplisit sebagai perangkat pengujian di testDeviceIdentifiers.
  • Perangkat dideklarasikan secara eksplisit sebagai perangkat pengujian di testDeviceIdentifiers.
  • Perangkat adalah simulator.
  • Perangkat dideklarasikan secara eksplisit sebagai perangkat pengujian di UI Ad Manager.

Bermigrasi dari v9 ke v10

Iklan berhenti ditayangkan di iOS 11

Google Mobile Ads SDK versi 10.0.0 hanya menayangkan iklan di perangkat yang menjalankan iOS 12 dan yang lebih tinggi.

Mengupgrade ke Google Mobile Ads SDK versi 10.0.0 tidak akan merusak aplikasi Anda di perangkat iOS 11 dan iOS 10, tetapi tidak ada iklan yang akan ditayangkan di perangkat tersebut.

Persyaratan ID Aplikasi Ad Manager

ID Aplikasi Ad Manager kini diperlukan di Info.plist untuk semua aplikasi Ad Manager dan memerlukan format ca-app-pub-################~##########. Lihat Memperbarui Info.plist untuk mengetahui detail selengkapnya.

Persyaratan GoogleAppMeasurement.xcframework

GoogleAppMeasurement.xcframework kini diperlukan untuk semua aplikasi Ad Manager. Jika Anda menginstal Google Mobile Ads SDK melalui Cocoapods atau Swift Package Manager, tidak ada tindakan tambahan yang diperlukan. Jika Anda menginstal framework secara manual, lihat Download Manual untuk mengetahui detail selengkapnya.

Mem-build dengan bitcode tidak lagi didukung

Menonaktifkan bitcode di aplikasi seluler kini diperlukan untuk mengintegrasikan Google Mobile Ads SDK.

Jenis dihapus

Jenis Catatan
GADGender Tidak ada pengganti.
GADMRewardBasedVideoAdNetworkAdapterProtocol Semua adaptor mediasi reward yang tercantum di Pilih Jaringan telah berhenti menggunakan protokol ini selama lebih dari setahun. Gunakan GADMediationAdapter untuk peristiwa kustom dan mediasi.
GADMRewardBasedVideoAdNetworkConnectorProtocol

Properti dihapus

Properti berikut dihapus tanpa penggantian.

Class v10.0.0 Properti
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

Bermigrasi dari v8 ke v9

Iklan berhenti ditayangkan di iOS 10

Versi iOS minimum yang didukung Google Mobile Ads SDK versi 9.0.0 adalah iOS 11.

Mengupgrade ke Google Mobile Ads SDK versi 9.0.0 tidak akan merusak aplikasi Anda di perangkat iOS 10, tetapi tidak ada iklan yang akan ditayangkan di perangkat tersebut.

Penerapan kontrol status bar yang lebih ketat

Mulai versi 9.0.0, saat Anda menampilkan iklan format layar penuh, aplikasi harus memastikan bahwa iklan dapat mengontrol presentasi status bar. Anda akan melihat pesan error dalam log jika gagal melakukannya.

Bergantung pada tata letak pengontrol tampilan tertentu di aplikasi, Anda mungkin tidak perlu melakukan perubahan apa pun untuk memastikannya. Pertimbangkan apakah Anda perlu menetapkan properti childViewControllerForStatusBarHidden di rootViewController iklan.

Mengganti nama adDidPresentFullScreenContent: menjadi adWillPresentFullScreenContent:

Tidak ada perubahan perilaku. Metode delegasi dipanggil tepat sebelum iklan akan ditampilkan, sehingga nama metode baru lebih mencerminkan fungsinya.

Menghapus API setelan lokasi di GADRequest

- (void)setLocationWithLatitude:longitude:accuracy: telah dihapus dari GADRequest karena data lokasi tidak digunakan oleh Google untuk menargetkan iklan. Gunakan API pihak ketiga untuk memberikan informasi kepada jaringan iklan pihak ketiga jika diperlukan.

Penghentian penggunaan antarmuka peristiwa kustom

Peristiwa kustom memungkinkan penayang yang menggunakan Mediasi Ad Manager untuk menambahkan mediasi waterfall bagi jaringan iklan yang bukan salah satu jaringan iklan yang didukung.

Semua protokol peristiwa kustom tidak digunakan lagi. Sebagai gantinya, gunakan protokol GADMediationAdapter dan GADMediationAdEventDelegate yang ada untuk mencapai fungsi yang sama. Perubahan ini meningkatkan kejelasan dan memungkinkan Anda membuat peristiwa kustom untuk iklan reward dan iklan interscroller yang sebelumnya tidak tersedia.

API

Tabel di bawah mencantumkan API adaptor mediasi yang sesuai dengan API peristiwa kustom yang harus digunakan mulai dari versi 9.0.0.

v8 v9
GADCustomEventBanner
GADCustomEventInterstitial
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationInterstitialAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate Delegasi ditampilkan oleh pengendali penyelesaian pemuatan dari setiap fungsi pemuatan class GADMediationAdapter
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
T/A -loadInterscrollerAdForAdConfiguration:completionHandler:
T/A -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

Metode delegasi

Tabel di bawah ini mencantumkan metode delegasi peristiwa iklan mediasi yang sesuai dengan metode delegasi peristiwa kustom yang harus digunakan mulai dari versi 9.0.0.

v8 v9
GADCustomEventBannerDelegate
GADCustomEventInterstitialDelegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate GADMediationAd
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
Status pemuatan iklan disertakan dalam pengendali penyelesaian pemuatan setiap fungsi pemuatan di class GADMediationAdapter
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

Metode dan konstanta lain yang dihapus/diganti

Perubahan pada metode, konstanta, atau properti
Konstanta dengan awalan kGAD- Dihapus. Gunakan konstanta dengan awalan GAD-.
GADAdNetworkResponseInfo credentials telah dihapus. Sebagai gantinya, gunakan adUnitMapping.
GAMRequest kGAMSimulatorID di GAMRequest tidak digunakan lagi. Sebagai gantinya, gunakan GADSimulatorID di GADRequestConfiguration.
GADCustomNativeAd mediaView di GADCustomNativeAd tidak digunakan lagi. Gunakan mediaContent sebagai gantinya.
In-App Purchase API di GoogleMobileAds inAppPurchase API di GoogleMobileAds telah dihapus.

Bermigrasi dari v7 ke v8

Google Mobile Ads SDK versi 8.0.0 memperkenalkan beberapa perubahan besar serta beberapa penggantian nama dan penghapusan API.

Update API format layar penuh

Mulai versi 8.0.0, iklan interstisial dan iklan reward memiliki iklan reward iklan layar Anda agar lebih konsisten. API iklan layar penuh yang baru ini memiliki dua perbedaan utama dengan API iklan layar penuh versi 7:

  1. Metode class statis load.

    Pendekatan sebelumnya untuk memuat/menampilkan iklan layar penuh adalah sebagai berikut:

    1. Membuat instance objek iklan dan memiliki referensi ke instance tersebut.
    2. Tetapkan delegasi yang menangani beban dan menampilkan callback.
    3. Muat iklan.
    4. Periksa apakah iklan dimuat menggunakan isReady.
    5. Menampilkan iklan.

    Pada versi 8, pendekatannya sedikit berubah. Callback pemuatan tidak lagi bagian dari delegasi. Sebaliknya, metode tersebut diteruskan ke metode load sebagai pengendali penyelesaian:

    1. Memanggil metode pemuatan statis di kelas iklan dan memberikan penyelesaian pemuatan sebagai pengendali
    2. Di callback penyelesaian pemuatan, simpan referensi ke iklan yang dimuat yang dikembalikan.
    3. Tetapkan delegasi yang menangani callback acara.
    4. Menampilkan iklan.

    Pendekatan baru ini memberikan manfaat berikut:

    • Anda tidak akan pernah memiliki referensi ke iklan yang tidak dimuat.
    • Anda tidak perlu berpegang pada objek iklan saat dimuat.
  2. Peristiwa iklan yang konsisten.

    Jenis peristiwa API yang sudah ada API v8
    Peristiwa pemuatan GADInterstitialDelegate atau GADRewardedAdDelegate GAMInterstitialAdLoadCompletionHandler atau GADRewardedAdLoadCompletionHandler
    Acara presentasi GADFullScreenContentDelegate

    Sebelumnya, untuk memproses peristiwa iklan, Anda perlu mendaftarkan kelas yang mengimplementasikan GADInterstitialDelegate ke properti delegasi interstisial, atau mendaftarkan class yang mengimplementasikan GADRewardedAdDelegate protokol ke properti delegasi iklan reward bergantung pada format yang yang Anda gunakan. Delegasi yang sama ini memiliki metode yang terkait dengan proses pemuatan dan siklus hidup presentasi iklan.

    Dengan versi 8, peristiwa pemuatan dan presentasi akan terpisah. Anda sekarang dapat daftarkan GADFullScreenContentDelegate kapan saja sebelum menampilkan iklan, dan tidak diharuskan untuk menetapkan satu sebelum memuat iklan. Peristiwa kepadatan iklan, yang spesifik untuk masing-masing besar, pindah ke pengendali penyelesaian pemuatan tunggal yang diteruskan dalam metode pemuatan.

Interstisial

Muat iklan

Cuplikan kode di bawah menunjukkan cara memuat iklan interstisial dan memprosesnya saat iklan berhasil atau gagal dimuat.

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;
  }];
}

Iklan Display

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");
  }
}

Peristiwa iklan presentasi

Cuplikan kode di bawah menunjukkan cara menangani callback saat iklan menyajikan (berhasil atau tidak berhasil) dan saat ditutup.

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.");
}

Reward

Muat iklan

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;
}

Iklan Display dan tangani reward

Iklan reward mengharuskan Anda untuk menangani peristiwa saat pengguna memperoleh reward. Dengan versi 7 dari GADRewardedAd API, Anda harus menerapkan rewardedAd:userDidEarnReward: sebagai bagian dari protokol GADRewardedAdDelegate. Untuk versi 8, Anda menerapkan GADUserDidEarnRewardHandler untuk menayangkan iklan.

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");
  }
}

Peristiwa iklan presentasi

Dengan GADRewardedAd API, Anda meneruskan GADRewardedAdDelegate ke metode tersebut yang menayangkan iklan. Dengan GADRewardedAd API, Anda dapat menetapkan GADFullscreenContentDelegate sebagai properti pada iklan sebelum menampilkan .

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.");
}

Penghapusan GADBerbasisVideoAd API lama

Lebih baru GADRewardedAd API pertama kali diperkenalkan pada Maret 2019 dan lebih disukai selama lebih dari 18 bulan. Memiliki lebih banyak peningkatan dibandingkan dengan versi sebelumnya GADRewardedBasedVideoAd API, termasuk kemampuan untuk memuat lebih dari satu API iklan reward pada satu waktu.

GADRewardedBasedVideoAd API lama dihapus di SDK versi 8.0.0.

Penghentian penggunaan banner cerdas dan penggunaan banner adaptif

Iklan banner cerdas tidak digunakan lagi dan menggantinya dengan banner adaptif iklan. Banner adaptif memberikan performa yang unggul dan yang lebih fleksibel dalam menetapkan lebar iklan. Jika Anda memilih untuk terus menggunakan banner lebar penuh, Anda dapat tetap dilakukan menggunakan banner adaptif, seperti yang ditunjukkan dalam cuplikan kode berikut:

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

Keluar dari penghapusan callback aplikasi

Callback willLeaveApplication untuk semua format iklan telah dihapus dan digantikan oleh applicationDidEnterBackground: dan sceneDidEnterBackground: metode. Menggunakan API level OS akan memberi tahu Anda setiap kali pengguna meninggalkan aplikasi, terlepas dari apakah itu disebabkan oleh interaksi iklan atau tidak.

Perhatikan bahwa callback willLeaveApplication tidak pernah dimaksudkan untuk pengendali klik iklan, dan mengandalkan callback ini untuk melaporkan klik tidak menghasilkan metrik yang akurat. Misalnya, klik pada AdChoices ikon yang meluncurkan browser eksternal memanggil callback tetapi tidak menghitung klik.

Penggantian nama kelas

Tabel di bawah ini mencantumkan nama-nama kelas tertentu yang telah berubah atau telah dihapus di versi 8. Rangkuman:

  • Semua class yang terkait dengan GADUnifiedNativeAd telah diganti namanya menjadi GADNativeAd.
  • GADRewardBasedVideoAd, GADNativeExpressAdView, dan GADInstreamAd memiliki telah dihapus.
  • Semua class dengan awalan DFP telah diganti dengan awalan GAM.
Class v7.68.0 Class 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 Dihapus
GADInterstitial GADInterstitialAd
GADNativeExpressAdView Dihapus
GADRewardBasedVideoAd Dihapus
GADInstreamAd Dihapus
GADInstreamAdView Dihapus

Metode dihapus/diganti

Tabel di bawah mencantumkan perubahan spesifik pada versi 8. Rangkuman:

  • Metode dan properti sebelumnya yang tidak digunakan lagi telah dihapus.
  • -willLeaveApplication: metode delegasi telah dihapus untuk semua format.
  • Nama kelas jaringan iklan telah dipindahkan ke properti GADResponseInfo.
  • ID perangkat pengujian telah dipindahkan ke GADRequestConfiguration saat ini.
Class v7.68.0 API v7.68.0 API v8.0.0 Catatan
GADMobileAds +configureWithApplicationID: -startWithCompletionHandler: ID aplikasi sekarang ditetapkan di Info.plist.
+disableAutomatedInAppPurchaseReporting -disableAutomatedInAppPurchaseReporting
+disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers Properti testDeviceIdentifiers berlaku untuk semua permintaan iklan, sedangkan properti testDevices lama ditetapkan per permintaan.
gender Dihapus
ulang tahun Dihapus
+sdkVersion GADMobileAds.sharedInstance.sdkVersion
-setBirthdayWithMonth:day:year: Dihapus
-setLocationWithDescription: -setLocationWithLatitude:longitude:accuracy:
-tagForChildDirectedTreatment: [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment]
GADErrorCode kGADError* GADError* Awalan k dihapus dari semua konstanta kode error.
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate Dihapus
mediatedAdView Dihapus
adNetworkClassName responseInfo.adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSizes:
DFPBannerViewOptions -adSizeDelegate Dihapus
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewWillPresentScreen: -bannerViewWillPresentScreen:
-adViewWillDismissScreen: -bannerViewWillDismissScreen:
-adViewDidDismissScreen: -bannerViewDidDismissScreen:
-adViewWillLeaveApplication: Dihapus
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate Dihapus
isReady Dihapus Sebagai gantinya, gunakan canPresentFromRootViewController:error:.
hasBeenUsed Dihapus
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialWillLeaveApplication: Dihapus
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName