Halaman ini membahas migrasi untuk versi saat ini dan sebelumnya.
Bermigrasi dari 10 ke v11
Target deployment minimum
Target deployment minimum telah ditingkatkan ke iOS 12.
Versi Xcode minimum
Versi Xcode minimum yang didukung telah dinaikkan ke 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 baru.
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 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:
- Iklan di layar pembuka aplikasi
- Interstisial
- Diberikan sebagai reward
- Interstisial reward
Parameter pengontrol tampilan di -canPresentFromRootViewController:error:
dan
-presentFromRootViewController:
bersifat nullable. Jika nilai nol diteruskan, iklan akan ditampilkan dari pengontrol tampilan teratas 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.
Kelas 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 pengganti.
Perubahan pada versi SDK logging
Versi 11.0.0 menghapus sdkVersion
. Untuk mencatat versi Google Mobile Ads SDK ke dalam log, gunakan versionNumber
.
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, metode ini
gagal setelah permintaan iklan dibuat.
Perubahan pada perilaku pengujian
Lihat tabel yang menampilkan kondisi yang diperbarui saat properti berikut menampilkan true
.
Class | 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 baru.
Upgrade ke Google Mobile Ads SDK versi 10.0.0 tidak akan merusak aplikasi Anda di perangkat iOS 11 dan iOS 10. Namun, iklan tidak 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 Mengupdate Info.plist untuk mengetahui detail selengkapnya.
Persyaratan GoogleAppMeasurement.xcframework
GoogleAppMeasurement.xcframework sekarang diperlukan untuk semua aplikasi Ad Manager. Jika Anda menginstal Google Mobile Ads SDK melalui Cocoapods atau Swift Package Manager, Anda tidak perlu melakukan tindakan tambahan. Jika Anda menginstal framework secara manual, lihat Download Manual untuk mengetahui detail selengkapnya.
Membuat aplikasi dengan bitcode tidak lagi didukung
Bitcode di aplikasi seluler Anda kini harus dinonaktifkan untuk mengintegrasikan Google Mobile Ads SDK.
Jenis dihapus
Jenis | Catatan |
---|---|
GADGender | Tidak ada pengganti. |
GADMRewardBasedVideoAdNetworkAdapterProtocol | Semua adaptor mediasi reward yang tercantum di Choose Networks telah berhenti menggunakan protokol ini selama lebih dari satu tahun. Gunakan GADMediationAdapter untuk mediasi dan peristiwa khusus. |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
Properti dihapus
Properti berikut dihapus tanpa pengganti.
Kelas 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.
Upgrade ke Google Mobile Ads SDK versi 9.0.0 tidak akan merusak aplikasi Anda di perangkat iOS 10, tetapi, iklan tidak akan ditayangkan di perangkat tersebut.
Penerapan kontrol status bar yang lebih ketat
Mulai versi 9.0.0, saat menayangkan iklan format layar penuh, aplikasi Anda harus memastikan bahwa iklan tersebut dapat mengontrol penyajian status bar. Anda akan melihat pesan error di log jika gagal melakukannya.
Bergantung pada tata letak khusus pengontrol tampilan di aplikasi, Anda mungkin tidak
perlu membuat perubahan untuk memastikan hal ini. Pertimbangkan apakah Anda perlu menetapkan 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 kepada jaringan iklan pihak ketiga, jika
diperlukan.
Penghentian antarmuka peristiwa kustom
Peristiwa kustom memungkinkan penayang menggunakan Ad Manager Mediasi untuk menambahkan mediasi waterfall untuk jaringan iklan yang bukan merupakan salah satu jaringan iklan yang didukung.
Semua protokol peristiwa kustom tidak digunakan lagi. Sebagai gantinya, gunakan protokol
GADMediationAdapter
dan
GADMediationAdEventDelegate
yang ada untuk mencapai fungsionalitas 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 ini mencantumkan API adaptor mediasi yang sesuai ke 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: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
T/A | -loadInterscrollerAdFor |
|
T/A | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
Metode delegasi
Tabel di bawah ini mencantumkan metode delegasi peristiwa iklan mediasi yang sesuai untuk metode delegasi peristiwa kustom yang harus digunakan mulai dari versi 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBannerDelegate GADCustomEventInterstitialDelegate GADCustomEventNativeAdDelegate |
GADMediationAdEventDelegate | IklanMediasi GAD |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd:
|
Status pemuatan iklan disertakan dalam pengendali penyelesaian pemuatan di 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 lainnya yang dihapus/diganti
Perubahan pada metode, konstanta, atau properti | |
---|---|
Konstanta berawalan kGAD-
|
Dihapus. Gunakan konstanta berawalan GAD- .
|
GADAdNetworkResponseInfo
|
credentials 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.
|
API Pembelian dalam Aplikasi 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 reward memiliki gaya iklan layar penuh yang sama agar lebih konsisten. API iklan layar penuh baru ini memiliki dua perbedaan besar dari API iklan layar penuh versi 7:
Metode class statis
load
.Pendekatan sebelumnya untuk memuat/menampilkan iklan layar penuh adalah sebagai berikut:
- Membuat instance objek iklan dan menyimpan referensi ke instance tersebut.
- Menetapkan delegasi yang menangani beban dan menampilkan callback.
- Muat iklan.
- Periksa apakah iklan dimuat menggunakan
isReady
. - Menampilkan iklan.
Pada versi 8, pendekatannya sedikit berubah. Callback pemuatan tidak lagi menjadi bagian dari delegasi. Sebagai gantinya, peristiwa tersebut akan diteruskan ke metode
load
sebagai pengendali penyelesaian:- Panggil metode pemuatan statis di class iklan dan sediakan pengendali penyelesaian beban.
- Dalam callback penyelesaian pemuatan, pertahankan referensi ke iklan yang dimuat dan ditampilkan.
- Menetapkan delegasi yang menangani callback acara.
- Menampilkan iklan.
Pendekatan baru memberikan manfaat berikut:
- Anda tidak akan memiliki referensi ke iklan yang tidak dimuat.
- Anda tidak perlu menahan objek iklan saat sedang dimuat.
Peristiwa iklan yang konsisten.
Jenis peristiwa API yang sudah ada API v8 Memuat peristiwa GADInterstitialDelegate
atauGADRewardedAdDelegate
GAMInterstitialAdLoadCompletionHandler
atauGADRewardedAdLoadCompletionHandler
Acara presentasi GADFullScreenContentDelegate
Sebelumnya, untuk memproses peristiwa iklan apa pun, Anda harus mendaftarkan class yang menerapkan protokol
GADInterstitialDelegate
ke properti delegasi interstisial, atau mendaftarkan class yang mengimplementasikan protokolGADRewardedAdDelegate
ke properti delegasi iklan reward, bergantung pada format yang Anda gunakan. Delegasi yang sama ini memiliki metode yang berkaitan dengan siklus proses pemuatan dan presentasi iklan.Pada versi 8, peristiwa pemuatan dan presentasi terpisah. Kini Anda dapat mendaftarkan
GADFullScreenContentDelegate
kapan saja sebelum menampilkan iklan, tanpa harus menetapkan satu delegasi sebelum memuat iklan. Peristiwa pemuatan iklan, yang khusus untuk setiap format, dipindahkan ke satu pengendali penyelesaian pemuatan yang diteruskan dalam metode pemuatan.
Interstisial
Muat iklan
Cuplikan kode di bawah ini 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 ini menunjukkan cara menangani callback saat iklan ditampilkan (berhasil atau tidak berhasil) dan saat iklan 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."); }
Diberikan sebagai 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; }
Tampilkan iklan dan tangani reward
Iklan reward mengharuskan Anda menangani peristiwa saat pengguna mendapatkan reward. Dengan
API GADRewardedAd
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 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 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
GADRewardedAd
API 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 GADRewardedBasedVideoAd
API lama, termasuk kemampuan untuk memuat lebih dari satu iklan reward sekaligus.
GADRewardedBasedVideoAd
API lama dihapus di SDK versi 8.0.0.
Penghentian banner cerdas dan banner adaptif
Iklan banner cerdas tidak digunakan lagi dan digantikan dengan iklan banner adaptif. Banner adaptif memberikan performa yang unggul dan fleksibilitas yang lebih baik dalam menetapkan lebar iklan. Jika Anda memilih untuk terus menggunakan banner dengan lebar penuh, hal tersebut 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
Keluar dari penghapusan callback aplikasi
Callback willLeaveApplication
untuk semua format iklan telah
dihapus dan diganti dengan metode
applicationDidEnterBackground:
dan
sceneDidEnterBackground:
. Penggunaan API tingkat OS akan memberi tahu Anda setiap kali pengguna keluar dari aplikasi, terlepas dari
apakah masalah tersebut disebabkan oleh interaksi iklan atau tidak.
Perhatikan bahwa callback willLeaveApplication
tidak pernah dimaksudkan untuk menjadi
pengendali 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.
Penggantian nama class
Tabel di bawah mencantumkan nama class tertentu yang telah diubah atau dihapus di versi 8. Ringkasan:
- Semua class yang terkait dengan
GADUnifiedNativeAd
telah diganti namanya menjadiGADNativeAd
. GADRewardBasedVideoAd
,GADNativeExpressAdView
, danGADInstreamAd
telah dihapus.- Semua class dengan awalan
DFP
telah diganti dengan awalanGAM
.
Kelas v7.68.0 | Kelas v8.0.0 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerViewOptions | GAMBannerViewOptions |
DFPInterstitial | Iklan GAMInterstitial |
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 dalam versi 8. Ringkasan:
- Metode dan properti yang sebelumnya 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 properti
GADRequestConfiguration
.
Kelas v7.68.0 | API v7.68.0 | API v8.0.0 | Catatan |
---|---|---|---|
GADMobileAds | +configureWithApplicationID: | {i>-startWithCompletionHandler:<i} | ID aplikasi sekarang 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 | ||
{i>-setLocationWithDescription:<i} | -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 | {i>-adSizeDelegate<i} | Dihapus | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
{i>-adView WillPresentScreen:<i} | -bannerViewWillPresentScreen: | ||
{i>-adView {/5}DismissScreen:<i} | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
{i>-adViewAllowLeadApplication<i}: | Dihapus | ||
GADNativeCustomTemplateAd | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GADNativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | Dihapus | |
isReady | Dihapus | Sebagai gantinya, gunakan canPresentFrom |
|
hasBeenUsed | Dihapus | ||
-init | {i>-initWithAdUnitID<i}: | ||
-setAdUnitID: | {i>-initWithAdUnitID<i}: | ||
adNetworkClassName | responseInfo |
||
-interstitial Will |
Dihapus | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |