Migracja pakietu SDK

Wybierz platformę: Android iOS Unity

Na tej stronie znajdziesz informacje o migracjach w przypadku bieżących i poprzednich wersji pakietu SDK do reklam mobilnych Google na iOS. Wersja 12.0.0 ma zostać wydana w lutym 2025 r.

Przejście z pakietu SDK w wersji 11 na wersję 12

Przejście na Xcode 16.0

Minimalna obsługiwana wersja Xcode to 16.0.

Obsługa nazewnictwa w języku Swift

Wersja 12.0.0 zawiera zmiany zgodne z konwencjami nazewnictwa w wytycznych dotyczących projektowania interfejsów API w Swift. Te zmiany dotyczą tylko Swift. Nie wprowadziliśmy żadnych zmian w nazwach interfejsów API Objective-C.

Zmiany prefiksów zajęć

W prefiksach zajęć wprowadziliśmy te zmiany:

  • Usunęliśmy przedrostek GAD z nazw wszystkich typów.
  • Zmieniono nazwę prefiksu GAM na AdManager.
  • Zmieniono nazwę prefiksu GADM na Mediation.

Rozwiązywanie problemów

Najlepszym sposobem na rozwiązanie problemów wynikających z tych zmian jest wprowadzenie poprawki.

Rozwiązywanie konfliktów nazw

Aby rozwiązać konflikty nazw, użyj przestrzeni nazw udostępnionej przez moduł. Na przykład GADRequest ma teraz nazwę Request. W tym przykładzie przestrzenie nazw klasy pakietu SDK do reklam mobilnych GoogleRequest:

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

Szczegółowa lista zmian w Swift

W tabelach poniżej znajdziesz listę zmian wprowadzonych w interfejsach API Swift:

Wersja 11 Wersja 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
Mediacja
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
Określanie stawek w czasie rzeczywistym
GADRTBAdapter RTBAdapter
GADRTBMediationSignalsConfiguration RTBMediationSignalsConfiguration
GADRTBRequestParameters RTBRequestParameters

Stałe

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

Właściwości

Typ Wersja 11 Wersja 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

Funkcje

Typ Wersja 11 Wersja 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:)
Mediacja
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:)

Zmiany w interfejsie API dotyczące sterowania stanem wyciszenia filmu

Właściwość isMuted i metoda setMute:GADVideoController zostały zastąpione właściwością muted.

Zmiany w przypadku wbudowanych reklam adaptacyjnych

Aby zoptymalizować wykorzystanie miejsca, adaptacyjne reklamy wstawiane początkowo nie zajmują miejsca w ramce. Wywołanie funkcji CGSizeFromGADAdSize(_:) z rozmiarem reklamy adaptacyjnej wstawionej w tekst zwraca teraz wysokość 0, dopóki pakiet SDK do reklam mobilnych Google nie zwróci reklamy.

Usunięto reklamy w wyszukiwarce niestandardowej

Te klasy zostały usunięte bez zastąpienia:

  • GADDynamicHeightSearchBannerView
  • GADDynamicHeightSearchRequest
  • GADSearchBannerView

Zmiany w kodach błędów

Zmienione kody błędów:

Klasa Uwagi
GADErrorMediationNoFill Błędy są teraz zwracane jako GADErrorNoFill.
GADErrorReceivedInvalidResponse Została zastąpiona przez GADErrorReceivedInvalidAdString.

Usunięto identyfikator GADSimulatorID

Użytkownik GADSimulatorID został usunięty. Symulatory są domyślnie w trybie testowym.

Zmiany w kierowaniu niestandardowym

Słownik customTargeting na stronie GADRequest używa teraz typu wartości Any zamiast String. Umożliwia to przekazywanie do interfejsu API wartości liczbowych.

Zmiany w parametrach dodatków

Migracja z wersji 10 do wersji 11

Minimalny cel wdrożenia

Minimalny cel wdrożenia został zwiększony do iOS 12.

Minimalna wersja Xcode

Minimalna obsługiwana wersja Xcode została zwiększona do 15.1.

Reklamy przestaną się wyświetlać w systemie iOS 12

Pakiet SDK do reklam mobilnych Google w wersji 11.0.0 wyświetla reklamy tylko na urządzeniach z systemem iOS 13 lub nowszym.

Usunięto zależność od GoogleAppMeasurement

W wersji 11.0.0 usunęliśmy zależność od GoogleAppMeasurement. Ta zależność, która umożliwiała działanie przełącznika danych o użytkownikach w AdMob, zostanie wycofana na początku 2024 roku. Aby nadal zbierać dane o użytkownikach w AdMob, połącz aplikację AdMob z Firebase i zintegruj z nią pakiet SDK Google Analytics dla Firebase.

Zmiany w sposobie wyświetlania reklam pełnoekranowych

Różne formaty reklam zostaną zmienione w ten sposób:

  • Reklama przy otwarciu aplikacji
  • Pełnoekranowa
  • Z nagrodą
  • Reklama pełnoekranowa z nagrodą

Parametr kontrolera widoku w -canPresentFromRootViewController:error:-presentFromRootViewController: może mieć wartość null. Jeśli przekazana zostanie wartość nil, reklama zostanie wyświetlona w najwyższym kontrolerze widoku w hierarchii kontrolerów widoku.

Usunięte metody

Usunęliśmy te metody:

Typ wersji 11.0.0 Metoda Uwagi
GADAppOpenAd load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) Zamiast niej używaj kolumny load(withAdUnitID adUnitID: String, request: GADRequest?).
GADMediationBannerAdEventDelegate willBackgroundApplication() Brak zamiennika.
GADMediationInterstitialAdEventDelegate willBackgroundApplication() Brak zamiennika.
GADMediationNativeAdEventDelegate willBackgroundApplication() Brak zamiennika.
GADMediationRewardedAdEventDelegate didRewardUser(with reward: GADAdReward) Zamiast niej używaj kolumny didRewardUser().
GADMediatedUnifiedNativeAdNotificationSource mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) Brak zamiennika.
GADRequestConfiguration setSameAppKeyEnabled(_ enabled: Bool) Zamiast niej używaj zasady setPublisherFirstPartyIDEnabled(_ enabled: Bool).
tagForUnderAge(ofConsent underAgeOfConsent: Bool) Zamiast tego użyj właściwości tagForUnderAgeOfConsent.
tag(forChildDirectedTreatment childDirectedTreatment: Bool) Zamiast tego użyj właściwości tagForChildDirectedTreatment.

Usunięte właściwości

Usunięte zostaną te właściwości:

Klasa v11.0.0 Właściwość Uwagi
GADMediationAdConfiguration hasUserLocation Brak zamiennika.
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment Zamiast niej używaj kolumny GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment.
GADResponseInfo adNetworkClassName Zamiast niej używaj zasady adNetworkClassName z sekcji loadedAdNetworkResponseInfo.

Usunięto GADAdFormatUnknown

Usunięto element GADAdFormatUnknown bez zastąpienia.

Zmiany w rejestrowaniu wersji pakietu SDK

Wersja 11.0.0 usuwa sdkVersion. Aby rejestrować wersję pakietu SDK do reklam mobilnych Google, użyj versionNumber.

Wersja 10.0.0

GADMobileAds.sharedInstance().sdkVersion

Wersja 11.0.0

GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)

Zmiany w obsłudze błędów w GADAdLoader

Od wersji 11.0.0 GADAdLoader nie wysyła żądania reklamy, jeśli jego delegate nie jest zgodny z protokołem delegata żądanych typów reklam. Wcześniej kończyło się niepowodzeniem po wysłaniu żądania reklamy.

Zmiany w sposobie testowania

W tabeli znajdziesz zaktualizowane warunki, w których przypadku te właściwości zwracają wartość true.

Klasa Właściwość
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • Urządzenie jest wyraźnie zadeklarowane jako urządzenie testowe w testDeviceIdentifiers.
  • Urządzenie jest wyraźnie zadeklarowane jako urządzenie testowe w testDeviceIdentifiers.
  • Urządzenie to symulator.
  • Urządzenie jest wyraźnie zadeklarowane jako urządzenie testowe w interfejsie AdMob.

Migracja z wersji 9 do wersji 10

Reklamy przestaną się wyświetlać w systemie iOS 11

Pakiet SDK do reklam mobilnych Google w wersji 10.0.0 wyświetla reklamy tylko na urządzeniach z iOS 12 lub nowszym.

Aktualizacja pakietu SDK do reklam mobilnych Google do wersji 10.0.0 nie spowoduje, że aplikacja przestanie działać na urządzeniach z iOS 11 i iOS 10, ale na tych urządzeniach nie będą się wyświetlać żadne reklamy.

Kompilowanie z bitkodem nie jest już obsługiwane

Aby zintegrować pakiet SDK do reklam mobilnych Google, musisz teraz wyłączyć kod pośredni w aplikacjach mobilnych.

Typy zostały usunięte

Typ Uwagi
GADGender Brak zamiennika.
GADMRewardBasedVideoAdNetworkAdapterProtocol Wszystkie adaptery zapośredniczenia reklam z nagrodą wymienione na stronie Wybierz sieci od ponad roku nie używają tych protokołów. Do mediacji i zdarzeń niestandardowych używaj GADMediationAdapter.
GADMRewardBasedVideoAdNetworkConnectorProtocol

Usunięte właściwości

Te właściwości zostaną usunięte bez zastąpienia.

Klasa v10.0.0 Właściwość
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

Migracja z wersji 8 na 9

Reklamy przestają się wyświetlać na urządzeniach z iOS 10

Minimalna wersja iOS obsługiwana przez pakiet SDK do reklam mobilnych Google w wersji 9.0.0 to iOS 11.

Aktualizacja pakietu SDK do reklam mobilnych Google do wersji 9.0.0 nie spowoduje, że aplikacja przestanie działać na urządzeniach z iOS 10, ale na tych urządzeniach nie będą się wyświetlać żadne reklamy.

Ścisłe egzekwowanie kontroli paska stanu

Od wersji 9.0.0, gdy wyświetlasz reklamy w formacie pełnoekranowym, aplikacja powinna zapewnić, że reklamy mogą kontrolować wyświetlanie paska stanu. Jeśli tego nie zrobisz, w dziennikach pojawi się komunikat o błędzie.

W zależności od konkretnego układu kontrolerów widoku w aplikacji może nie być konieczne wprowadzanie żadnych zmian, aby to zapewnić. Zastanów się, czy musisz ustawić właściwość childViewControllerForStatusBarHiddenrootViewController reklamy.

Zmień nazwę adDidPresentFullScreenContent: na adWillPresentFullScreenContent:

Nie ma zmian w działaniu. Metoda delegowania jest wywoływana tuż przed wyświetleniem reklamy, więc nowa nazwa metody lepiej odzwierciedla jej funkcjonalność.

Usuwanie interfejsu API ustawień lokalizacji w GADRequest

- (void)setLocationWithLatitude:longitude:accuracy: został usunięty z GADRequest, ponieważ Google nie używa danych o lokalizacji do kierowania reklam. W razie potrzeby używaj interfejsów API innych firm, aby przekazywać informacje do zewnętrznych sieci reklamowych.

Wycofanie interfejsów zdarzeń niestandardowych

Zdarzenia niestandardowe umożliwiają wydawcom korzystającym z zapośredniczenia AdMob dodawanie zapośredniczenia kaskadowego w przypadku sieci reklamowej, która nie jest jedną z obsługiwanych sieci reklamowych.

Wszystkie protokoły zdarzeń niestandardowych są wycofane. Zamiast tego używaj protokołów GADMediationAdapterGADMediationAdEventDelegate, aby uzyskać te same funkcje. Ta zmiana zwiększa przejrzystość i umożliwia tworzenie zdarzeń niestandardowych w przypadku reklam z nagrodą i reklam w przewijaniu, które wcześniej były niedostępne.

Interfejsy API

W tabeli poniżej znajdziesz odpowiednie interfejsy API adaptera do mediacji, które należy stosować w przypadku zdarzeń niestandardowych API od wersji 9.0.0.

v8 v9
GADCustomEventBanner
GADCustomEventInterstitial
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationInterstitialAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate Delegat jest zwracany przez moduł obsługi zakończenia wczytywania każdej funkcji wczytywania klasy GADMediationAdapter
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
Nie dotyczy -loadInterscrollerAdForAdConfiguration:completionHandler:
Nie dotyczy -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

Metody delegowania

W tabeli poniżej znajdziesz odpowiednie metody delegowania zdarzeń reklamowych w mediacji, które należy stosować od wersji 9.0.0 zamiast metod delegowania zdarzeń niestandardowych.

v8 v9
GADCustomEventBannerDelegate
GADCustomEventInterstitialDelegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate GADMediationAd
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
Stan wczytania reklamy jest uwzględniony w procedurze obsługi zakończenia wczytywania każdej funkcji wczytywania w klasie GADMediationAdapter.
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

Inne usunięte lub zastąpione metody i stałe

Zmiany metody, stałej lub właściwości
kGAD- stałych z prefiksem Usunięto. Używaj stałych z prefiksem GAD-.
GADAdNetworkResponseInfo Usunięto credentials. Zamiast tego użyj zasady adUnitMapping.
GADCustomNativeAd mediaViewGADCustomNativeAd zostało wycofane. Zamiast niej używaj zasady mediaContent.
Interfejsy API zakupów w aplikacji w GoogleMobileAds Interfejsy API inAppPurchaseGoogleMobileAds zostały usunięte.

Migracja z wersji 7 do wersji 8

Pakiet SDK do reklam mobilnych Google w wersji 8.0.0 wprowadza szereg istotnych zmian. Zmieniliśmy również nazwy kilku interfejsów API, a część z nich usunęliśmy.

Aktualizacje interfejsu API formatu pełnoekranowego

Od wersji 8.0.0 reklamy pełnoekranowe i z nagrodą mają wspólny styl, co zapewnia większą spójność. Te nowe interfejsy API reklam pełnoekranowych różnią się od interfejsów API reklam pełnoekranowych w wersji 7 w 2 głównych aspektach:

  1. Statyczna metoda klasyload.

    Poprzednie podejście do wczytywania i wyświetlania reklamy pełnoekranowej wyglądało tak:

    1. Utwórz instancję obiektu reklamy i zachowaj do niej odwołanie.
    2. Przypisz delegata, który będzie obsługiwać wywołania zwrotne wczytywania i wyświetlania.
    3. Wczytaj reklamę.
    4. Sprawdź, czy reklama została wczytana, za pomocą funkcji isReady.
    5. Wyświetl reklamę.

    W wersji 8 podejście to nieco się zmienia. Wywołania zwrotne wczytywania nie są już częścią delegata. Zamiast tego są przekazywane do metody load jako procedura obsługi zakończenia:

    1. Wywołaj statyczną metodę wczytywania w klasie reklamy i podaj procedurę obsługi zakończenia wczytywania.
    2. W wywołaniu zwrotnym zakończenia wczytywania zachowaj odniesienie do wczytanej reklamy, która jest zwracana.
    3. Przypisz osobę, która będzie obsługiwać wywołania zwrotne dotyczące wyświetleń.
    4. Wyświetl reklamę.

    Nowe podejście zapewnia te korzyści:

    • Nigdy nie będziesz mieć odniesienia do reklamy, która nie jest wczytana.
    • Podczas ładowania obiektu reklamy nie musisz go przechowywać.
  2. Spójne zdarzenia reklamowe

    Typ zdarzenia Istniejący interfejs API v8 API
    Zdarzenia wczytywania GADInterstitialDelegate lub GADRewardedAdDelegate GADInterstitialAdLoadCompletionHandler lub GADRewardedAdLoadCompletionHandler
    Zdarzenia prezentacji GADFullScreenContentDelegate

    Wcześniej, aby nasłuchiwać zdarzeń związanych z reklamami, należało zarejestrować klasę, która implementuje protokół GADInterstitialDelegate, we właściwości delegate reklamy pełnoekranowej lub zarejestrować klasę, która implementuje protokół GADRewardedAdDelegate, we właściwości delegate reklamy z nagrodą, w zależności od używanego formatu. Ten sam delegat miał metody związane zarówno z wczytywaniem, jak i z cyklem życia reklamy.

    W wersji 8 zdarzenia wczytywania i prezentacji są rozdzielone. Możesz teraz rejestrować GADFullScreenContentDelegate w dowolnym momencie przed wyświetleniem reklamy, zamiast ustawiać pojedynczego delegata przed wczytaniem reklamy. Zdarzenia wczytywania reklam, które są specyficzne dla każdego formatu, są przenoszone do jednego modułu obsługi zakończenia wczytywania przekazywanego w metodzie wczytywania.

Pełnoekranowa

Wczytaj reklamę

Poniższe fragmenty kodu pokazują, jak wczytać reklamę pełnoekranową i nasłuchiwać zdarzeń, gdy reklama zostanie wczytana lub nie.

wersja 7

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

Reklama displayowa

wersja 7

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

Zdarzenia dotyczące reklam w prezentacji

Poniższe fragmenty kodu pokazują, jak obsługiwać wywołania zwrotne w przypadku wyświetlenia reklamy (z powodzeniem lub nie) i jej zamknięcia.

wersja 7

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

Z nagrodą

Wczytaj reklamę

wersja 7

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

Wyświetlanie reklamy displayowej i obsługa nagrody

Reklamy z nagrodą wymagają obsługi zdarzenia, gdy użytkownik otrzyma nagrodę. W wersji 7 interfejsu API GADRewardedAd implementujesz rewardedAd:userDidEarnReward: w ramach protokołu GADRewardedAdDelegate. W wersji 8 implementujesz GADUserDidEarnRewardHandler, aby wyświetlać reklamę.

wersja 7

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

Zdarzenia dotyczące reklam w prezentacji

Za pomocą interfejsu GADRewardedAd API przekazujesz GADRewardedAdDelegate do metody, która wyświetla reklamę. Za pomocą GADRewardedAdinterfejsu APIGADFullscreenContentDelegate możesz ustawić jako właściwość reklamy przed jej wyświetleniem.

wersja 7

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

Usunięcie starszej wersji interfejsu GADRewardedBasedVideoAd API

Nowszy interfejs APIGADRewardedAd został wprowadzony w marcu 2019 r. i od ponad 18 miesięcy jest preferowanym interfejsem API do reklam z nagrodą. W porównaniu ze starszym interfejsem GADRewardedBasedVideoAd API ma więcej ulepszeń, w tym możliwość wczytywania więcej niż 1 reklamy z nagrodą naraz.

W pakiecie SDK w wersji 8.0.0 usunęliśmy starszy interfejs API GADRewardedBasedVideoAd.

Wycofanie banerów inteligentnych na rzecz banerów adaptacyjnych

Reklamy w inteligentnych banerach zostały wycofane na rzecz adaptacyjnych banerów. Banery adaptacyjne zapewniają większą skuteczność i elastyczność w ustawianiu szerokości reklamy. Jeśli wolisz nadal używać banerów o pełnej szerokości, możesz to zrobić za pomocą banera adaptacyjnego, jak pokazano w tym fragmencie kodu:

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

Usuwanie wywołania zwrotnego w przypadku opuszczenia aplikacji

willLeaveApplication wywołanie zwrotne dla wszystkich formatów reklam zostało usunięte na rzecz metod applicationDidEnterBackground: i sceneDidEnterBackground:. Korzystanie z interfejsów API na poziomie systemu operacyjnego, aby powiadamiać Cię, gdy użytkownicy opuszczają Twoją aplikację, niezależnie od tego, czy jest to spowodowane interakcją z reklamą.

Pamiętaj, że wywołanie zwrotne willLeaveApplication nigdy nie miało być obsługą kliknięć reklam, a korzystanie z niego do raportowania kliknięć nie dawało dokładnych danych. Na przykład kliknięcie ikony AdChoices, które spowodowało uruchomienie zewnętrznej przeglądarki, wywołało wywołanie zwrotne, ale nie zostało zliczone jako kliknięcie.

Zmiany nazw zajęć

W tabeli poniżej znajdziesz listę konkretnych nazw klas, które zostały zmienione lub usunięte w wersji 8. Podsumowanie:

  • Wszystkie zajęcia związane z GADUnifiedNativeAd zostały zmienione na GADNativeAd.
  • Usunięto funkcje GADRewardBasedVideoAd, GADNativeExpressAdView i GADInstreamAd.
  • Wszystkie klasy z prefiksem DFP zostały zastąpione prefiksem GAM.
Klasa v7.68.0 Klasa 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 Usunięto
GADInterstitial GADInterstitialAd
GADNativeExpressAdView Usunięto
GADRewardBasedVideoAd Usunięto
GADInstreamAd Usunięto
GADInstreamAdView Usunięto

Usunięte lub zastąpione metody

W tabeli poniżej znajdziesz szczegółowe informacje o zmianach wprowadzonych w wersji 8. Podsumowanie:

  • Wycofane wcześniej metody i właściwości zostały usunięte.
  • Metody przekazywania -willLeaveApplication: zostały usunięte ze wszystkich formatów.
  • Nazwa klasy sieci reklamowej została przeniesiona do właściwości GADResponseInfo.
  • Identyfikator urządzenia testowego został przeniesiony do usługi GADRequestConfiguration.
Klasa v7.68.0 Interfejs API w wersji 7.68.0 API w wersji 8.0.0 Uwagi
GADMobileAds +configureWithApplicationID: -startWithCompletionHandler: Identyfikator aplikacji został ustawiony w pliku Info.plist.
+disableAutomatedInAppPurchaseReporting -disableAutomatedInAppPurchaseReporting
+disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers Właściwość testDeviceIdentifiers ma zastosowanie do wszystkich żądań reklam, a właściwość testDevices była ustawiana dla każdego żądania z osobna.
płeć Usunięto
urodziny Usunięto
+sdkVersion GADMobileAds.sharedInstance.sdkVersion
-setBirthdayWithMonth:day:year: Usunięto
-setLocationWithDescription: -setLocationWithLatitude:longitude:accuracy:
-tagForChildDirectedTreatment: [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment]
GADErrorCode kGADError* GADError* Prefiks k jest usuwany ze wszystkich stałych kodów błędów.
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate Usunięto
mediatedAdView Usunięto
adNetworkClassName responseInfo.adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSizes:
DFPBannerViewOptions -adSizeDelegate Usunięto
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewWillPresentScreen: -bannerViewWillPresentScreen:
-adViewWillDismissScreen: -bannerViewWillDismissScreen:
-adViewDidDismissScreen: -bannerViewDidDismissScreen:
-adViewWillLeaveApplication: Usunięto
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate Usunięto
isReady Usunięto Zamiast niej używaj metody canPresentFromRootViewController:error:.
hasBeenUsed Usunięto
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialWillLeaveApplication: Usunięto
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName