Questa pagina riguarda le migrazioni delle versioni attuali e precedenti dell'applicazione l'SDK Mobile Ads per iOS. Il rilascio della versione 11.0.0 è previsto per gennaio 2024.
Esegui la migrazione dalla versione v10 dell'SDK alla v11
Destinazione di deployment minima
La destinazione minima di deployment è stata aumentata a iOS 12.
Versione minima di Xcode
La versione minima di Xcode supportata è stata aumentata alla versione 15.1.
Interruzione della pubblicazione degli annunci su iOS 12
La versione 11.0.0 dell'SDK Google Mobile Ads consente di pubblicare gli annunci solo su dispositivi con iOS 13 e versioni successive.
Dipendenza GoogleAppMeasurement rimossa
Nella versione 11.0.0, la dipendenza da GoogleAppMeasurement
è stata rimossa. Questa dipendenza alla base del pulsante di attivazione/disattivazione delle metriche utente in AdMob verrà disattivata all'inizio del 2024. Per continuare a raccogliere metriche utente in AdMob, collega la tua app AdMob a Firebase e integra l'SDK Google Analytics for Firebase nella tua app.
Modifiche alla presentazione dell'annuncio a schermo intero
Le seguenti modifiche influiscono sui vari formati degli annunci:
- Apertura app
- Interstitial
- Con premio
- Interstitial con premio
Il parametro del controller di visualizzazione in -canPresentFromRootViewController:error:
e
-presentFromRootViewController:
è nullo. Se viene passato zero, l'annuncio viene presentato
dal controller di visualizzazione più in alto nella gerarchia del controller di visualizzazione.
Metodi rimossi
I seguenti metodi vengono rimossi.
v11.0.0 Tipo | Metodo | Note |
---|---|---|
Annuncio aperto app GAD | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) |
Usa invece load(withAdUnitID adUnitID: String, request: GADRequest?) . |
GADMediationBannerAdEventDelegate | willBackgroundApplication() |
Nessuna sostituzione. |
GADMediationInterstitialAdEventDelegate | willBackgroundApplication() |
Nessuna sostituzione. |
GADMediationNativeAdEventDelegate | willBackgroundApplication() |
Nessuna sostituzione. |
GADMediationRewardedAdEventDelegate | didRewardUser(with reward: GADAdReward) |
Usa invece didRewardUser() . |
GADMediatedUnifiedNativeAdNotificationSource | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) |
Nessuna sostituzione. |
GADRequestConfiguration | setSameAppKeyEnabled(_ enabled: Bool) |
Usa invece il criterio setPublisherFirstPartyIDEnabled(_ enabled: Bool) . |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) |
Utilizza la proprietà tagForUnderAgeOfConsent . |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
Utilizza la proprietà tagForChildDirectedTreatment . |
Proprietà rimosse
Le seguenti proprietà sono state rimosse.
Classe v11.0.0 | Proprietà | Note |
---|---|---|
GADMediationAdConfiguration | hasUserLocation | Nessuna sostituzione. |
userLatitude | ||
userLongitude | ||
userLocationAccuracyInMeters | ||
childDirectedTreatment | Usa invece GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment . |
|
GADResponseInfo | adNetworkClassName | Usa invece il criterio adNetworkClassName di loadedAdNetworkResponseInfo . |
Rimosso formato dell'annuncio GADSconosciuto
GADAdFormatUnknown
rimosso senza sostituzione.
Modifiche alla versione dell'SDK di Logging
La versione 11.0.0 rimuove sdkVersion
. Per registrare la versione dell'SDK Google Mobile Ads, utilizza versionNumber
.
Versione 10.0.0
GADMobileAds.sharedInstance().sdkVersion
Versione 11.0.0
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
Modifiche alla gestione degli errori di GADAdLoader
A partire dalla versione 11.0.0, GADAdLoader
non effettua una richiesta di annuncio se il suo
delegate
non è conforme al protocollo di delega dei tipi di annuncio richiesti. In precedenza, non andava a buon fine dopo aver effettuato la richiesta di annuncio.
Modifiche al comportamento dei test
Consulta la tabella che mostra le condizioni aggiornate per quando le seguenti
proprietà restituiscono true
.
Classe | Proprietà |
---|---|
GADMediationAdConfiguration | isTestRequest |
GADCustomEventRequest | isTesting |
v10.0.0 | v11.0.0 |
|
|
Migrazione dalla versione 9 alla versione 10
La pubblicazione degli annunci viene interrotta su iOS 11
L'SDK Google Mobile Ads versione 10.0.0 pubblica annunci solo su dispositivi con iOS 12 e versioni successive.
L'upgrade all'SDK Google Mobile Ads versione 10.0.0 non interromperà la tua app sui dispositivi iOS 11 e iOS 10, ma non verranno pubblicati annunci su questi dispositivi.
La creazione con bitcode non è più supportata
Per integrare l'SDK Google Mobile Ads, ora devi disattivare il bitcode nelle app mobile.
Tipi rimossi
Tipo | Note |
---|---|
GADGender | Nessuna sostituzione. |
GADMRewardBasedVideoAdNetworkAdapterProtocol | Tutti gli adattatori di mediazione con premio elencati nella pagina Scegli le reti non usano più questi protocolli da oltre un anno. Utilizza GADMediationAdapter per la mediazione e gli eventi personalizzati. |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
Proprietà rimosse
Le seguenti proprietà vengono rimosse senza sostituzione.
Classe v10.0.0 | Proprietà |
---|---|
GADMediationAdRequest | userBirthday |
userGender | |
userHasLocation | |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription | |
GADCustomEventRequest | userHasLocation |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription |
Migrazione da v8 a v9
La pubblicazione degli annunci viene interrotta su iOS 10
La versione di iOS minima supportata dall'SDK Google Mobile Ads versione 9.0.0 è iOS 11.
L'upgrade all'SDK Google Mobile Ads versione 9.0.0 non interromperà la tua app sui dispositivi iOS 10, ma non verranno pubblicati annunci su questi dispositivi.
Applicazione più rigorosa dei controlli della barra di stato
A partire dalla versione 9.0.0, quando presenti annunci in formato a schermo intero, la tua app deve garantire che gli annunci siano in grado di controllare la visualizzazione della barra di stato. Se non esegui questa operazione, verrà visualizzato un messaggio di errore nei log.
A seconda del layout specifico dei controller di visualizzazione nella tua app, potrebbe non essere necessario apportare modifiche per garantire che ciò accada. Valuta se è necessario impostare la proprietà childViewControllerForStatusBarHidden
nella proprietà rootViewController
del tuo annuncio.
Rinomina adDidPresentFullScreenContent: in adWillPresentFullScreenContent:
Non c'è alcun cambiamento di comportamento. Il metodo delegato viene richiamato subito prima che l'annuncio sta per essere presentato, quindi il nuovo nome del metodo riflette meglio la sua funzionalità.
Rimuovi l'API di impostazione della località su GADRequest
- (void)setLocationWithLatitude:longitude:accuracy:
è stato eliminato da
GADRequest
perché Google non utilizza i dati sulla posizione per il targeting degli annunci. Utilizza
API di terze parti per fornire le informazioni a reti pubblicitarie di terze parti, se
necessario.
Ritiro delle interfacce evento personalizzate
Gli eventi personalizzati consentono ai publisher che utilizzano AdMob Mediazione di aggiungere la mediazione con struttura a cascata per una rete pubblicitaria che non fa parte delle reti pubblicitarie supportate.
Tutti i protocolli di eventi personalizzati sono deprecati. Utilizza invece i protocolli GADMediationAdapter
e GADMediationAdEventDelegate
esistenti per ottenere le stesse funzionalità. Questa modifica migliora la chiarezza e consente di creare eventi personalizzati per gli annunci con premio e gli annunci interscroller che non erano disponibili in precedenza.
API
La tabella riportata di seguito elenca le API dell'adattatore di mediazione corrispondenti alle API degli eventi personalizzati da utilizzare a partire dalla versione 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBanner GADCustomEventInterstitial GADCustomEvent NativeAnnuncio |
GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediazione Annuncio con premio GADMediazioneNativoAnnuncio |
delegate
|
Il delegato viene restituito dal gestore del completamento del caricamento di ogni funzione di caricamento
della classe GADMediationAdapter
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
N/A | -loadInterscrollerAdFor |
|
N/A | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
Delega metodi
Nella tabella seguente sono elencati i metodi di delega degli eventi dell'annuncio di mediazione corrispondenti ai metodi di delega degli eventi personalizzati da utilizzare a partire dalla versione 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBannerDelega GADCustomEventInterstitial fiducia GADCustomEvent NativeAd fiducia |
GADMediationAdEventDelegate | Annuncio di mediazione GAD |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd:
|
Lo stato del carico degli annunci è incluso nel gestore di completamento del caricamento di
ogni funzione di caricamento nella classe GADMediationAdapter
|
|
-customEventBanner:didFailAd: -customEventInterstitial:didFailAd:
|
||
-customEventBannerWasClicked: -customEventInterstitialWasClicked:
|
-reportClick |
|
-customEventBannerWill -customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid -customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
Altri metodi e costanti rimossi/sostituiti
Modifiche al metodo, alla costante o alla proprietà | |
---|---|
kGAD- costanti con prefisso
|
Rimosso. Utilizza le costanti con prefisso GAD- .
|
GADAdNetworkResponseInfo
|
Sono stati rimossi credentials . Usa invece adUnitMapping .
|
GAMRequest
|
L'API kGAMSimulatorID in GAMRequest è deprecata.
Usa invece GADSimulatorID in GADRequestConfiguration .
|
GADCustomNativeAd
|
L'API mediaView in GADCustomNativeAd è deprecata.
Usa invece il criterio mediaContent .
|
API In-App Purchase in GoogleMobileAds |
inAppPurchase API in GoogleMobileAds sono state
rimosse.
|
Migrazione da v7 a v8
La versione 8.0.0 dell'SDK Google Mobile Ads introduce alcuni cambiamenti importanti nonché alcune ridenominazioni e rimozioni di API.
Aggiornamenti dell'API per il formato a schermo intero
A partire dalla versione 8.0.0, gli annunci interstitial e con premio condividono uno stile dell'annuncio generico a schermo intero per una maggiore coerenza. Queste nuove API per gli annunci a schermo intero presentano due principali distinzioni rispetto alle API annunci a schermo intero della versione 7:
Metodo della classe statica
load
.Il precedente approccio per caricare/mostrare un annuncio a schermo intero è il seguente:
- Crea un'istanza dell'oggetto annuncio e mantieni un riferimento all'oggetto.
- Assegna un delegato che gestisca il carico e mostri i callback.
- Carica un annuncio.
- Controlla se l'annuncio è stato caricato utilizzando
isReady
. - Mostra l'annuncio.
Nella versione 8, l'approccio cambia leggermente. I callback di carico non fanno più parte di un delegato. Vengono invece trasferiti al metodo
load
come gestore dei completamenti:- Richiama un metodo di caricamento statico nella classe dell'annuncio e fornisci un gestore di completamento del caricamento.
- Nel callback di completamento del caricamento, mantieni un riferimento all'annuncio caricato restituito.
- Assegna un delegato che gestisce i callback di visualizzazione.
- Mostra l'annuncio.
Il nuovo approccio offre i seguenti vantaggi:
- Non avrai mai un riferimento a un annuncio che non è stato caricato.
- Non è necessario tenere premuto un oggetto dell'annuncio durante il caricamento.
Eventi pubblicitari coerenti.
Tipo di evento API esistente API v8 Eventi di caricamento GADInterstitialDelegate
oppureGADRewardedAdDelegate
GADInterstitialAdLoadCompletionHandler
oppureGADRewardedAdLoadCompletionHandler
Eventi di presentazione GADFullScreenContentDelegate
In precedenza, per ascoltare gli eventi relativi agli annunci, dovevi registrare una classe che implementa il protocollo
GADInterstitialDelegate
per la proprietà delegata di un annuncio interstitial o una classe che implementa il protocolloGADRewardedAdDelegate
sulla proprietà delegata di un annuncio con premio, a seconda del formato che stai utilizzando. Lo stesso delegato disponeva di metodi relativi sia al ciclo di vita di caricamento sia a quello di presentazione di un annuncio.Nella versione 8, gli eventi di caricamento e di presentazione sono separati. Ora puoi registrare un
GADFullScreenContentDelegate
in qualsiasi momento prima di mostrare un annuncio, invece di dover impostare un singolo delegato prima di caricare l'annuncio. Gli eventi di caricamento degli annunci, specifici di ciascun formato, vengono spostati in un singolo gestore di completamento del caricamento trasmesso nel metodo di caricamento.
Interstitial
Carica annuncio
Gli snippet di codice riportati di seguito mostrano come caricare un annuncio interstitial e ascoltare gli eventi quando l'annuncio viene caricato correttamente o meno.
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: GADInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") interstitial.delegate = self let request = GADRequest() interstitial.load(request) } /// Tells the delegate an ad request succeeded. func interstitialDidReceiveAd(_ ad: GADInterstitial) { print("Interstitial ad loaded.") } /// Tells the delegate an ad request failed. func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) { print("Interstitial ad failed to load with error: \(error.localizedDescription)") } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADInterstitial *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"]; self.interstitial.delegate = self; GADRequest *request = [GADRequest request]; [self.interstitial loadRequest:request]; } /// Tells the delegate an ad request succeeded. - (void)interstitialDidReceiveAd:(GADInterstitial *)ad { NSLog(@"Insterstitial ad loaded."); } /// Tells the delegate an ad request failed. - (void)interstitial:(GADInterstitial *)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: GADInterstitialAd? override func viewDidLoad() { super.viewDidLoad() let request = GADRequest() GADInterstitialAd.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) GADInterstitialAd *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GADRequest *request = [GADRequest request]; [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910" request:request completionHandler:^(GADInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]); return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; }
Annuncio 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"); } }
Eventi annuncio di presentazione
Gli snippet di codice riportati di seguito mostrano come gestire i callback per quando l'annuncio viene mostrato (riuscita o meno) e quando viene ignorato.
v7
Swift
override func viewDidLoad() { super.viewDidLoad() interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910") interstitial.delegate = self ... } /// Tells the delegate that an interstitial will be presented. func interstitialWillPresentScreen(_ ad: GADInterstitial) { print("Interstitial ad will be presented.") } /// Tells the delegate the interstitial is to be animated off the screen. func interstitialWillDismissScreen(_ ad: GADInterstitial) { print("Interstitial ad will be dismissed.") } /// Tells the delegate the interstitial had been animated off the screen. func interstitialDidDismissScreen(_ ad: GADInterstitial) { 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: GADInterstitial) { print("Interstitial ad will leave application.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:"ca-app-pub-3940256099942544/4411468910"]; self.interstitial.delegate = self; ... } /// Tells the delegate that an interstitial will be presented. - (void)interstitialWillPresentScreen:(GADInterstitial *)ad { NSLog(@"Interstitial ad will be presented."); } /// Tells the delegate the interstitial is to be animated off the screen. - (void)interstitialWillDismissScreen:(GADInterstitial *)ad { NSLog(@"Interstitial ad will be dismissed."); } /// Tells the delegate the interstitial had been animated off the screen. - (void)interstitialDidDismissScreen:(GADInterstitial *)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:(GADInterstitial *)ad { NSLog(@"Interstitial ad will leave application."); }
v8
Swift
override func viewDidLoad() { super.viewDidLoad() let request = GADRequest() GADInterstitialAd.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]; GADRequest *request = [GADRequest request]; [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910" request:request completionHandler:^(GADInterstitialAd *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."); }
Con premio
Carica annuncio
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(GADRequest()) { 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; GADRequest *request = [GADRequest 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 = GADRequest() 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]; GADRequest *request = [GADRequest 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; }
Visualizza l'annuncio e gestisci il premio
Gli annunci con premio richiedono che tu gestisca l'evento nel momento in cui un utente guadagna un premio. Con la versione 7 dell'API GADRewardedAd
, implementi rewardedAd:userDidEarnReward:
come parte del protocollo GADRewardedAdDelegate
.
Per la versione 8, devi implementare GADUserDidEarnRewardHandler
per
presentare l'annuncio.
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"); } }
Eventi annuncio di presentazione
Con l'API GADRewardedAd
passi un GADRewardedAdDelegate
al metodo
che presenta l'annuncio. Con l'API GADRewardedAd
, puoi impostare una GADFullscreenContentDelegate
come proprietà nell'annuncio prima di presentarlo.
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 = GADRequest() 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]; GADRequest *request = [GADRequest 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."); }
Rimozione dell'API GADRewardedBasedVideoAd precedente
La più recente
API GADRewardedAd
è stata introdotta per la prima volta a marzo 2019 ed è stata l'API con premio preferita da oltre 18 mesi. Ha apportato più miglioramenti rispetto all'API GADRewardedBasedVideoAd
legacy, tra cui la possibilità di caricare più di un annuncio con premio alla volta.
L'API GADRewardedBasedVideoAd
precedente è stata rimossa nella versione 8.0.0 dell'SDK.
Ritiro dei banner intelligenti a favore di quelli adattivi
Gli annunci banner intelligenti sono stati ritirati a favore degli annunci banner adattivi. I banner adattivi offrono prestazioni superiori e maggiore flessibilità nell'impostazione della larghezza dell'annuncio. Se preferisci continuare a utilizzare i banner a larghezza intera, puoi farlo utilizzando i banner adattivi, come mostrato nel seguente snippet di codice:
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
Abbandona la rimozione del callback dell'applicazione
Il willLeaveApplication
callback per tutti i formati degli annunci è stato rimosso a favore dei metodi applicationDidEnterBackground:
e sceneDidEnterBackground:
. L'utilizzo di API a livello di sistema operativo ti avvisa ogni volta che gli utenti abbandonano la tua app, indipendentemente dal fatto che sia dovuto o meno a un'interazione con l'annuncio.
Tieni presente che il willLeaveApplication
callback non è mai stato pensato come gestore di clic sugli annunci e l'utilizzo di questo callback per registrare i clic non ha prodotto una metrica accurata. Ad esempio, un clic sull'icona Scegli Tu! che ha avviato un browser esterno ha richiamato il callback ma non ha conteggiato un clic.
Rinominazioni dei corsi
La tabella seguente elenca i nomi delle classi specifici che sono stati modificati o sono stati rimossi nella versione 8. In sintesi:
- Tutti i corsi relativi a
GADUnifiedNativeAd
sono stati rinominati comeGADNativeAd
. GADRewardBasedVideoAd
,GADNativeExpressAdView
eGADInstreamAd
sono stati rimossi.- Tutte le classi con il prefisso
DFP
sono state sostituite con un prefissoGAM
.
Classe v7.68.0 | Classe v8.0.0 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerViewOptions | GAMBannerViewOptions |
DFPInterstitial | Annuncio interstitial GAM |
DFPRequest | GAMRequest |
GADRequestError | NSError |
GADUnifiedNativeAdView | GADNativeAdView |
Annuncio nativo-unificato GAD | Annuncio nativo-GAD |
GADUnifiedNativeAdAssetIdentifiers | GADNativeAdAssetIdentifiers |
GADUnifiedNativeAdDelegate | GADNativeAdDelegate |
GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
Annuncio modello GAD NativeCustom | Annuncio nativo personalizzato GAD |
GADNativeCustomTemplateAdLoaderDelegate | GADCustomNativeAdLoaderDelegate |
GADNativeAdDelegate | GADCustomNativeAdDelegate |
GADInAppPurchase | Rimosso |
GADInterstitial | Annuncio interstitial GAD |
GADNativeExpressAdView | Rimosso |
Annuncio video basato sul premio GAD | Rimosso |
Annuncio in-stream GAD | Rimosso |
GADInstreamAdView | Rimosso |
Metodi rimossi/sostituiti
La tabella seguente elenca le modifiche specifiche nella versione 8. In sintesi:
- I metodi e le proprietà che erano stati ritirati in precedenza sono stati rimossi.
-willLeaveApplication:
metodi delegati sono stati rimossi per tutti i formati.- Il nome della classe della rete pubblicitaria è stato spostato nella proprietà
GADResponseInfo
. - L'identificatore del dispositivo di test è stato spostato nella proprietà
GADRequestConfiguration
.
Classe v7.68.0 | API v7.68.0 | API v8.0.0 | Note |
---|---|---|---|
Annunci per cellulari GAD | +configureWithApplicationID: | -startWithCompleteHandler: | L'ID app è ora impostato in Info.plist. |
+disableAutomatedInApp |
-disableAutomatedInApp |
||
+disableSDKCrashReporting | -disableSDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
La proprietà testDeviceIdentifiers si applica a tutte le richieste di annuncio, mentre la precedente proprietà testDevices era impostata a livello di richiesta. |
genere | Rimosso | ||
compleanno | Rimosso | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
Rimosso | ||
-setLocationWithDescription: | -setLocationWith |
||
-tagForChildDirectedTreatment: | [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment] | ||
GADErrorCode | Errore kGAD* | Errore GAD* | Il prefisso k viene eliminato da tutte le costanti del codice di errore.
|
GADBannerView | hasAutoRefreshed | autoloadEnabled | |
inAppPurchaseDelegate | Rimosso | ||
mediatedAdView | Rimosso | ||
adNetworkClassName | rispostaInfo |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerViewOptions | -adSizeDelega | Rimosso | |
GADBannerViewDelegate | -adViewDidReachAd: | -bannerViewDidReceivedAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
-adViewWillDeployScreen: | -bannerViewWillDeployScreen: | ||
-adViewDidIgnoraScreen: | -bannerViewDidIgnoraScreen: | ||
-adViewWillLeaveApplication: | Rimosso | ||
Annuncio modello GAD NativeCustom | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GAD NativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | Rimosso | |
isReady | Rimosso | Usa canPresentFrom |
|
hasBeenUsed | Rimosso | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | rispostaInfo |
||
-interstitial |
Rimosso | ||
Annuncio nativo-unificato GAD | videoController | mediaContent.videoController | |
adNetworkClassName | rispostaInfo |