Halaman ini membahas migrasi untuk Google Mobile Ads SDK untuk iOS versi 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 mencakup perubahan untuk mengikuti konvensi penamaan dalam Pedoman Desain API Swift. Perubahan ini hanya memengaruhi Swift. Tidak ada perubahan penamaan yang dilakukan pada API Objective-C.
Perubahan awalan class
Perubahan berikut telah dilakukan pada awalan class:
- Menghapus awalan
GAD
di seluruh nama untuk semua jenis. - Mengganti nama awalan
GAM
menjadiAdManager
. - Mengganti nama awalan
GADM
menjadiMediation
.
Mengatasi error
Cara terbaik untuk mengatasi error yang dihasilkan dari perubahan ini adalah dengan melakukan koreksi Fix-It.
Mengatasi konflik penamaan
Untuk mengatasi konflik penamaan, gunakan namespace yang disediakan oleh modul. Misalnya, GADRequest
sekarang bernama Request
. Contoh namespace berikut
kelas Google Mobile Ads SDK Request
:
import GoogleMobileAds
...
var request: GoogleMobileAds.Request?
Daftar perubahan Swift yang mendetail
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:) |
Menetapkan parameter penargetan kustom
Untuk menetapkan penargetan kustom pada permintaan iklan, gunakan
customTargeting
.
Perubahan API untuk mengontrol status senyap 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 frame. Memanggil CGSizeFromGADAdSize(_:)
dengan
ukuran iklan adaptif inline kini menampilkan tinggi 0
hingga Google Mobile Ads
SDK menampilkan iklan.
Menghapus iklan penelusuran khusus
Class berikut dihapus tanpa penggantian:
GADDynamicHeightSearchBannerView
GADDynamicHeightSearchRequest
GADSearchBannerView
Perubahan pada kode error
Kode error berikut telah diubah:
Kelas | Catatan |
---|---|
GADErrorMediationNoFill |
Sekarang error 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. Dengan cara ini, Anda dapat meneruskan nilai numerik ke API.
Perubahan pada parameter tambahan
- Meneruskan kunci ke
additionalParameters
tidak lagi menerapkan penargetan kustom ke permintaan iklan Ad Manager. Untuk menerapkan penargetan kustom, lihat penargetan kustom.
- Penerusan tombol
max_ad_content_rating
keadditionalParameters
tidak lagi didukung. Untuk menetapkan rating konten iklan maksimum, lihat pemfilteran konten iklan.
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 yang mendukung tombol metrik pengguna di AdMob ini akan
dihentikan pada awal tahun 2024. Untuk
terus mengumpulkan metrik pengguna di AdMob,
tautkan aplikasi AdMob 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:
dapat bernilai null. Jika nil diteruskan, iklan akan ditampilkan dari pengontrol tampilan paling atas dalam hierarki pengontrol tampilan.
Metode dihapus
Metode berikut dihapus.
v11.0.0 Type | 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) |
Gunakan properti tagForUnderAgeOfConsent sebagai gantinya. |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
Gunakan properti tagForChildDirectedTreatment sebagai gantinya. |
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 pencatatan versi SDK
Versi 11.0.0 menghapus sdkVersion
. Untuk mencatat versi Google Mobile Ads SDK,
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
-nya
tidak sesuai dengan protokol delegasi jenis iklan yang diminta. Sebelumnya, permintaan iklan gagal setelah permintaan iklan dibuat.
Perubahan pada perilaku pengujian
Lihat tabel yang menunjukkan kondisi yang diperbarui untuk saat properti berikut menampilkan true
.
Kelas | Properti |
---|---|
GADMediationAdConfiguration | isTestRequest |
GADCustomEventRequest | isTesting |
v10.0.0 | v11.0.0 |
|
|
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 Anda
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 detail selengkapnya.
Membangun 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 adapter mediasi reward yang tercantum di Pilih Jaringan telah berhenti menggunakan protokol ini selama lebih dari setahun. Gunakan GADMediationAdapter untuk mediasi dan peristiwa kustom. |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
Properti dihapus
Properti berikut dihapus tanpa penggantian.
v10.0.0 Class | 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 dari versi 9.0.0, saat Anda menampilkan iklan format layar penuh, aplikasi Anda harus memastikan bahwa iklan dapat mengontrol presentasi status bar. Anda akan melihat pesan error di log jika gagal melakukannya.
Bergantung pada tata letak spesifik pengontrol tampilan di aplikasi, Anda mungkin tidak
perlu melakukan perubahan apa pun untuk memastikannya. Pertimbangkan apakah Anda perlu menyetel
properti childViewControllerForStatusBarHidden
di rootViewController
iklan Anda.
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 ke jaringan iklan pihak ketiga jika
diperlukan.
Penghentian penggunaan antarmuka peristiwa kustom
Peristiwa kustom memungkinkan penayang yang menggunakan Mediasi Ad Manager menambahkan mediasi waterfall untuk 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
|
Delegate ditampilkan oleh pengendali penyelesaian pemuatan setiap fungsi pemuatan
class GADMediationAdapter
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
T/A | -loadInterscrollerAdFor |
|
T/A | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
Metode delegasi
Tabel di bawah 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 |
|
-customEventBannerWill -customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid -customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
Metode dan konstanta lain yang dihapus/diganti
Perubahan pada metode, konstanta, atau properti | |
---|---|
Konstanta dengan awalan kGAD-
|
Dihapus. Gunakan konstanta berawalan 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 |
API inAppPurchase di GoogleMobileAds telah dihapus.
|
Bermigrasi dari v7 ke v8
Google Mobile Ads SDK versi 8.0.0 menghadirkan sejumlah perubahan besar serta beberapa perubahan nama dan penghapusan API.
Update API format layar penuh
Mulai versi 8.0.0, iklan interstisial dan iklan reward berbagi gaya iklan layar penuh generik untuk konsistensi yang lebih baik. API iklan layar penuh baru ini memiliki dua perbedaan utama dari API iklan layar penuh versi 7:
Metode class statis
load
.Pendekatan sebelumnya untuk memuat/menampilkan iklan layar penuh adalah sebagai berikut:
- Buat instance objek iklan dan simpan referensinya.
- Tetapkan delegasi yang menangani callback pemuatan dan penayangan.
- Muat iklan.
- Periksa apakah iklan dimuat menggunakan
isReady
. - Tampilkan iklan.
Pada versi 8, pendekatan berubah sedikit. Callback pemuatan tidak lagi menjadi bagian dari delegasi. Sebagai gantinya, nilai tersebut diteruskan ke metode
load
sebagai handler penyelesaian:- Panggil metode pemuatan statis pada class iklan dan berikan pengendali penyelesaian pemuatan.
- Dalam callback penyelesaian pemuatan, simpan referensi ke iklan yang dimuat yang ditampilkan.
- Tetapkan delegasi yang menangani callback tampilan.
- Tampilkan iklan.
Pendekatan baru ini memberikan manfaat berikut:
- Anda tidak akan pernah memiliki referensi ke iklan yang tidak dimuat.
- Anda tidak perlu mempertahankan objek iklan saat sedang dimuat.
Peristiwa iklan yang konsisten.
Jenis peristiwa API yang ada API v8 Peristiwa pemuatan GADInterstitialDelegate
atauGADRewardedAdDelegate
GAMInterstitialAdLoadCompletionHandler
atauGADRewardedAdLoadCompletionHandler
Peristiwa presentasi GADFullScreenContentDelegate
Sebelumnya, untuk memproses peristiwa iklan apa pun, Anda akan mendaftarkan class yang menerapkan protokol
GADInterstitialDelegate
ke properti delegasi iklan interstisial, atau mendaftarkan class yang menerapkan protokolGADRewardedAdDelegate
ke properti delegasi iklan bersponsor, bergantung pada format yang Anda gunakan. Delegasi yang sama ini memiliki metode yang terkait dengan siklus proses pemuatan dan presentasi iklan.Dengan versi 8, peristiwa pemuatan dan presentasi terpisah. Anda kini dapat mendaftarkan
GADFullScreenContentDelegate
kapan saja sebelum menampilkan iklan, bukan diwajibkan untuk menetapkan satu delegasi sebelum memuat iklan. Peristiwa pemuatan iklan, yang khusus untuk setiap format, berpindah ke pengendali penyelesaian pemuatan tunggal yang diteruskan dalam metode pemuatan.
Interstisial
Memuat iklan
Cuplikan kode di bawah menunjukkan cara memuat iklan interstisial dan memproses peristiwa 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 ditampilkan (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
Memuat 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; }
Menampilkan iklan dan menangani reward
Iklan reward mengharuskan Anda menangani peristiwa saat pengguna memperoleh reward. Dengan
GADRewardedAd
API versi 7, Anda menerapkan
rewardedAd:userDidEarnReward:
sebagai bagian dari protokol GADRewardedAdDelegate
.
Untuk versi 8, Anda menerapkan GADUserDidEarnRewardHandler
untuk menampilkan 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
yang menampilkan iklan. Dengan GADRewardedAd
API, Anda menetapkan
GADFullscreenContentDelegate
sebagai properti pada iklan sebelum menampilkan
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 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 GADRewardedBasedVideoAd API lama
API
GADRewardedAd
yang lebih baru pertama kali diperkenalkan pada Maret 2019 dan telah menjadi API reward pilihan selama lebih dari 18 bulan. API ini memiliki lebih banyak peningkatan dibandingkan dengan API GADRewardedBasedVideoAd
lama, termasuk kemampuan untuk memuat lebih dari satu iklan reward sekaligus.
API GADRewardedBasedVideoAd
lama dihapus di SDK versi 8.0.0.
Penghentian penggunaan banner smart untuk mendukung banner adaptif
Iklan banner smart tidak digunakan lagi dan digantikan dengan iklan banner adaptif. Banner adaptif memberikan performa yang lebih baik dan fleksibilitas yang lebih tinggi dalam menetapkan lebar iklan. Jika Anda lebih memilih untuk terus menggunakan banner lebar penuh, hal itu masih dapat 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
Menghapus callback aplikasi keluar
Callback willLeaveApplication
untuk semua format iklan telah dihapus dan digantikan dengan metode applicationDidEnterBackground:
dan sceneDidEnterBackground:
. Menggunakan API tingkat OS akan memberi tahu Anda setiap kali pengguna keluar dari aplikasi, terlepas dari
apakah hal itu disebabkan oleh interaksi iklan atau tidak.
Perhatikan bahwa callback willLeaveApplication
tidak pernah dimaksudkan untuk menjadi
handler klik iklan, dan mengandalkan callback ini untuk melaporkan klik tidak
menghasilkan metrik yang akurat. Misalnya, klik pada ikon AdChoices yang meluncurkan browser eksternal memanggil callback, tetapi tidak menghitung klik.
Mengganti nama kelas
Tabel di bawah ini mencantumkan nama class tertentu yang telah berubah atau dihapus di versi 8. Rangkuman:
- Semua class yang terkait dengan
GADUnifiedNativeAd
telah diganti namanya menjadiGADNativeAd
. GADRewardBasedVideoAd
,GADNativeExpressAdView
, danGADInstreamAd
telah dihapus.- Semua class dengan awalan
DFP
telah diganti dengan awalanGAM
.
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 ini mencantumkan perubahan spesifik dalam versi 8. Rangkuman:
- Metode dan properti yang sebelumnya tidak digunakan lagi telah dihapus.
- Metode delegasi
-willLeaveApplication:
telah dihapus untuk semua format. - Nama class jaringan iklan telah dipindahkan ke properti
GADResponseInfo
. - ID perangkat pengujian telah dipindahkan ke properti
GADRequestConfiguration
.
Class v7.68.0 | API v7.68.0 | API v8.0.0 | Catatan |
---|---|---|---|
GADMobileAds | +configureWithApplicationID: | -startWithCompletionHandler: | ID aplikasi kini ditetapkan di Info.plist. |
+disableAutomatedInApp |
-disableAutomatedInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
Properti testDeviceIdentifiers berlaku untuk semua permintaan iklan, sedangkan properti testDevices lama ditetapkan per permintaan. |
gender | Dihapus | ||
ulang tahun | Dihapus | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
Dihapus | ||
-setLocationWithDescription: | -setLocationWith |
||
-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 |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerViewOptions | -adSizeDelegate | Dihapus | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillLeaveApplication: | Dihapus | ||
GADNativeCustomTemplateAd | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GADNativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | Dihapus | |
isReady | Dihapus | Sebagai gantinya, gunakan canPresentFrom |
|
hasBeenUsed | Dihapus | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | responseInfo |
||
-interstitialWill |
Dihapus | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |