การย้ายข้อมูล SDK

หน้านี้ครอบคลุมการย้ายข้อมูลสำหรับ SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google สำหรับ iOS เวอร์ชันปัจจุบันและเวอร์ชันก่อนหน้า คาดว่าเวอร์ชัน 12.0.0 จะเปิดตัวในเดือนกุมภาพันธ์ 2025

ย้ายข้อมูลจาก v11 ไปยัง v12

อัปเกรดเป็น Xcode 16.0

เวอร์ชัน Xcode ขั้นต่ำที่รองรับเพิ่มขึ้นเป็น 16.0

การรองรับการตั้งชื่อของ Swift

เวอร์ชัน 12.0.0 มีการเปลี่ยนแปลงเพื่อปฏิบัติตามรูปแบบการตั้งชื่อใน API Design Guidelines ของ Swift การเปลี่ยนแปลงเหล่านี้มีผลกับ Swift เท่านั้น ไม่มีการเปลี่ยนแปลงชื่อ Objective-C API

การเปลี่ยนแปลงคำนำหน้าของคลาส

มีการเปลี่ยนแปลงต่อไปนี้กับคำนำหน้าชั้นเรียน

  • นำคำนำหน้า GAD ออกจากชื่อของทุกประเภท
  • เปลี่ยนชื่อคำนำหน้า GAM เป็น AdManager
  • เปลี่ยนชื่อคำนำหน้า GADM เป็น Mediation

แก้ไขข้อผิดพลาด

วิธีที่ดีที่สุดในการแก้ไขข้อผิดพลาดที่เกิดจากการเปลี่ยนแปลงเหล่านี้คือการทำการแก้ไข

แก้ไขความขัดแย้งในการตั้งชื่อ

หากต้องการแก้ไขข้อขัดแย้งในการตั้งชื่อ ให้ใช้เนมสเปซที่โมดูลระบุ เช่น GADRequest เปลี่ยนชื่อเป็น Request แล้ว ตัวอย่างเนมสเปซต่อไปนี้เป็นคลาส Request ของ Google Mobile Ads SDK

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

รายการการเปลี่ยนแปลง Swift โดยละเอียด

ตารางต่อไปนี้แสดงการเปลี่ยนแปลงที่เกิดขึ้นกับ Swift API

เวอร์ชัน 11 เวอร์ชัน 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
สื่อกลาง
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
การเสนอราคาแบบเรียลไทม์
GADRTBAdapter RTBAdapter
GADRTBMediationSignalsConfiguration RTBMediationSignalsConfiguration
GADRTBRequestParameters RTBRequestParameters

ค่าคงที่

เวอร์ชัน 11 เวอร์ชัน 12
GADAdLoaderAdType.gamBanner AdLoaderAdType.adManagerBanner
GADAdSizeBanner AdSizeBanner
GADAdSizeFluid AdSizeFluid
GADAdSizeFullBanner AdSizeFullBanner
GADAdSizeInvalid AdSizeInvalid
GADAdSizeLargeBanner AdSizeLargeBanner
GADAdSizeLeaderboard AdSizeLeaderboard
GADAdSizeMediumRectangle AdSizeMediumRectangle
GADAdSizeSkyscraper AdSizeSkyscraper
GoogleMobileAdsVersionString GoogleMobileAdsVersion

พร็อพเพอร์ตี้

ประเภท เวอร์ชัน 11 เวอร์ชัน 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

ฟังก์ชัน

ประเภท เวอร์ชัน 11 เวอร์ชัน 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:)
สื่อกลาง
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:)

การเปลี่ยนแปลง API ในการควบคุมสถานะการปิดเสียงวิดีโอ

พร็อพเพอร์ตี้ isMuted และเมธอด setMute: ใน GADVideoController นั้นถูกแทนที่ด้วยพร็อพเพอร์ตี้ muted

การเปลี่ยนแปลงโฆษณาแบบปรับขนาดได้ในบรรทัด

โฆษณาแบบปรับเปลี่ยนในบรรทัดจะไม่ใช้พื้นที่ในเฟรมในตอนแรกเพื่อเพิ่มประสิทธิภาพการใช้พื้นที่ การเรียกใช้ CGSizeFromGADAdSize(_:) ด้วยขนาดโฆษณาแบบปรับขนาดได้ในบรรทัดตอนนี้จะแสดงผลความสูง 0 จนกว่า SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google จะแสดงโฆษณา

นําโฆษณา Search ที่กําหนดเองออกแล้ว

ระบบจะนำคลาสต่อไปนี้ออกโดยไม่มีคลาสอื่นมาแทนที่

  • GADDynamicHeightSearchBannerView
  • GADDynamicHeightSearchRequest
  • GADSearchBannerView

การเปลี่ยนแปลงรหัสข้อผิดพลาด

รหัสข้อผิดพลาดต่อไปนี้มีการเปลี่ยนแปลง

ระดับ หมายเหตุ
GADErrorMediationNoFill ตอนนี้ข้อผิดพลาดจะแสดงเป็น GADErrorNoFill
GADErrorReceivedInvalidResponse แทนที่ด้วย GADErrorReceivedInvalidAdString

นํา GADSimulatorID ออกแล้ว

นำ GADSimulatorID ออกแล้ว โดยค่าเริ่มต้น เครื่องจำลองจะอยู่ในโหมดทดสอบอยู่แล้ว

การเปลี่ยนแปลงการกำหนดเป้าหมายเอง

ตอนนี้พจนานุกรม customTargeting ใน GADRequest ใช้ Any เป็นประเภทค่าแทน String ซึ่งจะช่วยให้คุณส่งค่าตัวเลขไปยัง API ได้

การเปลี่ยนแปลงพารามิเตอร์พิเศษ

ย้ายข้อมูลจาก v10 ไปยัง v11

เป้าหมายการทำให้ใช้งานได้ขั้นต่ำ

เป้าหมายการทำให้ใช้งานได้ขั้นต่ำได้เพิ่มขึ้นเป็น iOS 12 แล้ว

เวอร์ชัน Xcode ขั้นต่ำ

เวอร์ชัน Xcode ขั้นต่ำที่รองรับได้เพิ่มขึ้นเป็น 15.1

โฆษณาหยุดแสดงใน iOS 12

SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google เวอร์ชัน 11.0.0 จะแสดงโฆษณาในอุปกรณ์ที่ใช้ iOS 13 ขึ้นไปเท่านั้น

นำการพึ่งพา GoogleAppMeasurement ออก

ในเวอร์ชัน 11.0.0 ระบบได้นำการขึ้นต่อกันกับ GoogleAppMeasurement ออกแล้ว เราจะหยุดให้บริการการพึ่งพานี้ซึ่งขับเคลื่อนปุ่มสลับเมตริกผู้ใช้ใน AdMob ช่วงต้นปี 2024 หากต้องการรวบรวมเมตริกผู้ใช้ใน AdMob ต่อไป ให้ลิงก์แอป AdMob กับ Firebase และผสานรวม SDK ของ Google Analytics สําหรับ Firebase เข้ากับแอป

การเปลี่ยนแปลงการแสดงโฆษณาแบบเต็มหน้าจอ

การเปลี่ยนแปลงต่อไปนี้มีผลต่อโฆษณารูปแบบต่างๆ

  • การเปิดแอป
  • โฆษณาคั่นระหว่างหน้า
  • ได้รับรางวัลแล้ว
  • โฆษณาคั่นระหว่างหน้าที่มีการให้รางวัล

พารามิเตอร์ตัวควบคุมมุมมองใน -canPresentFromRootViewController:error: และ -presentFromRootViewController: มีค่า Null ได้ หากส่งค่าเป็น "nil" ระบบจะแสดงโฆษณาจากวิดเจ็ตที่ด้านบนสุดในลําดับชั้นของวิดเจ็ต

วิธีการที่ถูกนำออก

ระบบจะนำเมธอดต่อไปนี้ออก

ประเภท v11.0.0 วิธีการ หมายเหตุ
GADAppOpenAd load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) ให้ใช้ load(withAdUnitID adUnitID: String, request: GADRequest?) แทน
GADMediationBannerAdEventDelegate willBackgroundApplication() ไม่มีการแทนที่
GADMediationInterstitialAdEventDelegate willBackgroundApplication() ไม่มีการแทนที่
GADMediationNativeAdEventDelegate willBackgroundApplication() ไม่มีการแทนที่
GADMediationRewardedAdEventDelegate didRewardUser(with reward: GADAdReward) ให้ใช้ didRewardUser() แทน
GADMediatedUnifiedNativeAdNotificationSource mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) ไม่มีการแทนที่
GADRequestConfiguration setSameAppKeyEnabled(_ enabled: Bool) โปรดใช้ setPublisherFirstPartyIDEnabled(_ enabled: Bool) แทน
tagForUnderAge(ofConsent underAgeOfConsent: Bool) ให้ใช้พร็อพเพอร์ตี้ tagForUnderAgeOfConsent แทน
tag(forChildDirectedTreatment childDirectedTreatment: Bool) ให้ใช้พร็อพเพอร์ตี้ tagForChildDirectedTreatment แทน

ที่พักที่นำออก

ระบบจะนำพร็อพเพอร์ตี้ต่อไปนี้ออก

คลาส v11.0.0 พร็อพเพอร์ตี้ หมายเหตุ
GADMediationAdConfiguration hasUserLocation ไม่มีการแทนที่
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment ให้ใช้ GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment แทน
GADResponseInfo adNetworkClassName ให้ใช้ adNetworkClassName จาก loadedAdNetworkResponseInfo แทน

นํา GADAdFormatUnknown ออกแล้ว

นำ GADAdFormatUnknown ออกโดยไม่มีการแทนที่

การเปลี่ยนแปลงการบันทึกเวอร์ชัน SDK

เวอร์ชัน 11.0.0 จะนํา sdkVersion ออก หากต้องการบันทึกเวอร์ชัน Google Mobile Ads SDK ให้ใช้ versionNumber แทน

เวอร์ชัน 10.0.0

GADMobileAds.sharedInstance().sdkVersion

เวอร์ชัน 11.0.0

GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)

การเปลี่ยนแปลงการจัดการข้อผิดพลาดของ GADAdLoader

ตั้งแต่เวอร์ชัน 11.0.0 GADAdLoader จะไม่ส่งคําขอโฆษณาหาก delegate ไม่เป็นไปตามโปรโตคอลของตัวแทนของประเภทโฆษณาที่ขอ ก่อนหน้านี้ การดำเนินการนี้ไม่สำเร็จหลังจากส่งคำขอโฆษณา

การเปลี่ยนแปลงลักษณะการทดสอบ

ดูตารางที่แสดงเงื่อนไขที่อัปเดตแล้วเมื่อพร็อพเพอร์ตี้ต่อไปนี้แสดงผลเป็น true

ระดับ พร็อพเพอร์ตี้
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • มีการประกาศอุปกรณ์เป็นอุปกรณ์ทดสอบอย่างชัดเจนใน testDeviceIdentifiers
  • มีการประกาศอุปกรณ์เป็นอุปกรณ์ทดสอบอย่างชัดเจนใน testDeviceIdentifiers
  • อุปกรณ์เป็นเครื่องจำลอง
  • มีการประกาศอุปกรณ์เป็นอุปกรณ์ทดสอบอย่างชัดเจนใน UI ของ Ad Manager

ย้ายข้อมูลจาก v9 ไปยัง v10

โฆษณาหยุดแสดงใน iOS 11

SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google เวอร์ชัน 10.0.0 จะแสดงโฆษณาในอุปกรณ์ที่ใช้ iOS 12 ขึ้นไปเท่านั้น

การอัปเกรดเป็น Google Mobile Ads SDK เวอร์ชัน 10.0.0 จะไม่ทําให้แอปของคุณใช้งานไม่ได้ในอุปกรณ์ iOS 11 และ iOS 10 แต่โฆษณาจะไม่แสดงในอุปกรณ์เหล่านั้น

ข้อกําหนดของรหัสแอป Ad Manager

ตอนนี้แอป Ad Manager ทั้งหมดต้องใช้รหัสแอป Ad Manager ใน Info.plist และต้องใช้รูปแบบ ca-app-pub-################~########## ดูรายละเอียดเพิ่มเติมได้ที่อัปเดต Info.plist

ข้อกําหนดของ GoogleAppMeasurement.xcframework

ตอนนี้แอป Google Ad Manager ทั้งหมดต้องใช้ GoogleAppMeasurement.xcframework หากติดตั้ง SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google ผ่าน Cocoapods หรือ Swift Package Manager คุณไม่จําเป็นต้องดําเนินการใดๆ เพิ่มเติม หากติดตั้งเฟรมเวิร์กด้วยตนเอง โปรดดูรายละเอียดเพิ่มเติมที่หัวข้อการดาวน์โหลดด้วยตนเอง

ระบบไม่รองรับการสร้างด้วยบิตโค้ดอีกต่อไป

ตอนนี้คุณต้องปิดใช้บิตโค้ดในแอปบนอุปกรณ์เคลื่อนที่เพื่อผสานรวม Google Mobile Ads SDK

ประเภทที่นําออก

ประเภท หมายเหตุ
GADGender ไม่มีการแทนที่
GADMRewardBasedVideoAdNetworkAdapterProtocol อะแดปเตอร์สื่อกลางที่มีการให้รางวัลทั้งหมดที่แสดงใน Choose Networks ได้หยุดใช้โปรโตคอลเหล่านี้มานานกว่า 1 ปีแล้ว ใช้ GADMediationAdapter สําหรับสื่อกลางและเหตุการณ์ที่กําหนดเอง
GADMRewardBasedVideoAdNetworkConnectorProtocol

ที่พักที่นำออก

ระบบจะนำพร็อพเพอร์ตี้ต่อไปนี้ออกโดยไม่มีการแทนที่

คลาส v10.0.0 พร็อพเพอร์ตี้
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

ย้ายข้อมูลจาก v8 ไปยัง v9

โฆษณาหยุดแสดงใน iOS 10

iOS เวอร์ชันขั้นต่ำที่ Google Mobile Ads SDK เวอร์ชัน 9.0.0 รองรับคือ iOS 11

การอัปเกรดเป็น Google Mobile Ads SDK เวอร์ชัน 9.0.0 จะไม่ทําให้แอปของคุณใช้งานไม่ได้ในอุปกรณ์ iOS 10 แต่โฆษณาจะไม่แสดงในอุปกรณ์เหล่านั้น

การบังคับใช้การควบคุมแถบสถานะที่เข้มงวดยิ่งขึ้น

ตั้งแต่เวอร์ชัน 9.0.0 เป็นต้นไป เมื่อคุณแสดงโฆษณารูปแบบเต็มหน้าจอ แอปของคุณควรตรวจสอบว่าโฆษณาสามารถควบคุมการแสดงแถบสถานะได้ คุณจะเห็นข้อความแสดงข้อผิดพลาดในบันทึกหากดำเนินการไม่สำเร็จ

คุณอาจไม่จําเป็นต้องทําการเปลี่ยนแปลงใดๆ เพื่อให้แน่ใจถึงเรื่องนี้ ทั้งนี้ขึ้นอยู่กับเลย์เอาต์ที่เฉพาะเจาะจงของวิดเจ็ตควบคุมมุมมองในแอป พิจารณาว่าคุณต้องตั้งค่าพร็อพเพอร์ตี้ childViewControllerForStatusBarHidden ใน rootViewController ของโฆษณาหรือไม่

เปลี่ยนชื่อ adDidPresentFullScreenContent: เป็น adWillPresentFullScreenContent:

ไม่มีการเปลี่ยนแปลงลักษณะการทำงาน ระบบจะเรียกใช้เมธอดนี้ทันทีก่อนที่โฆษณาจะแสดง ดังนั้นชื่อเมธอดใหม่จึงสะท้อนถึงฟังก์ชันการทํางานได้ดียิ่งขึ้น

นํา API การตั้งค่าตําแหน่งใน GADRequest ออก

- (void)setLocationWithLatitude:longitude:accuracy: ถูกลบออกจาก GADRequest เนื่องจาก Google ไม่ได้ใช้ข้อมูลตําแหน่งเพื่อกําหนดเป้าหมายโฆษณา ใช้ API ของบุคคลที่สามเพื่อส่งข้อมูลไปยังเครือข่ายโฆษณาบุคคลที่สาม หากจำเป็น

การเลิกใช้งานอินเทอร์เฟซเหตุการณ์ที่กําหนดเอง

เหตุการณ์ที่กําหนดเองช่วยให้ผู้เผยแพร่โฆษณาที่ใช้สื่อกลาง Ad Manager เพิ่มการแสดงโฆษณาสื่อกลางตามลำดับขั้นสําหรับเครือข่ายโฆษณาที่ไม่ใช่เครือข่ายโฆษณาที่รองรับได้

เลิกใช้งานโปรโตคอลเหตุการณ์ที่กําหนดเองทั้งหมดแล้ว แต่ให้ใช้โปรโตคอล GADMediationAdapter และ GADMediationAdEventDelegate ที่มีอยู่เพื่อให้ได้ฟังก์ชันการทำงานแบบเดียวกัน การเปลี่ยนแปลงนี้ช่วยเพิ่มความชัดเจนและช่วยให้คุณสร้างเหตุการณ์ที่กําหนดเองสําหรับโฆษณาที่มีการให้รางวัลและโฆษณาระหว่างหน้าเว็บได้ ซึ่งก่อนหน้านี้ไม่สามารถทำได้

API

ตารางด้านล่างแสดงรายการ API ของ Mediation Adapter ที่สอดคล้องกันกับเหตุการณ์ที่กําหนดเองซึ่งควรใช้ตั้งแต่เวอร์ชัน 9.0.0 เป็นต้นไป

v8 v9
GADCustomEventBanner
GADCustomEventInterstitial
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationInterstitialAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate ตัวแปรที่รับค่ามาได้จากตัวแฮนเดิลการโหลดที่เสร็จสมบูรณ์ของฟังก์ชันการโหลดแต่ละรายการของคลาส GADMediationAdapter
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
ไม่มี -loadInterscrollerAdForAdConfiguration:completionHandler:
ไม่มี -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

วิธีการมอบสิทธิ์

ตารางด้านล่างแสดงเมธอดของเหตุการณ์โฆษณาสื่อกลางที่รับมอบสิทธิ์ที่เกี่ยวข้องซึ่งควรใช้ตั้งแต่เวอร์ชัน 9.0.0 เป็นต้นไป

v8 v9
GADCustomEventBannerDelegate
GADCustomEventInterstitialDelegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate GADMediationAd
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
สถานะการโหลดโฆษณาจะรวมอยู่ในตัวแฮนเดิลการโหลดที่เสร็จสมบูรณ์ของฟังก์ชันการโหลดแต่ละรายการในคลาส GADMediationAdapter
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

เมธอดและค่าคงที่อื่นๆ ที่นําออก/แทนที่

การเปลี่ยนแปลงเมธอด ค่าคงที่ หรือพร็อพเพอร์ตี้
kGAD- ค่าคงที่ที่มีคำนำหน้า นำออกแล้ว ใช้ค่าคงที่ที่มีGAD-นำหน้า
GADAdNetworkResponseInfo ระบบนำ credentials รายการออกแล้ว ให้ใช้ adUnitMapping instead.
GAMRequest kGAMSimulatorID ใน GAMRequest เลิกใช้งานแล้ว ให้ใช้ GADSimulatorID ใน GADRequestConfigurationแทน
GADCustomNativeAd mediaView ใน GADCustomNativeAd เลิกใช้งานแล้ว โปรดใช้ mediaContent แทน
In-App Purchase API ใน GoogleMobileAds ระบบนำ inAppPurchase API ใน GoogleMobileAds ออกแล้ว

ย้ายข้อมูลจาก v7 ไปยัง v8

SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google เวอร์ชัน 8.0.0 มีการเปลี่ยนแปลงที่สำคัญ รวมไปถึงการเปลี่ยนชื่อ API และการนำ API ออก

การอัปเดต API รูปแบบแบบเต็มหน้าจอ

ตั้งแต่เวอร์ชัน 8.0.0 เป็นต้นไป โฆษณาคั่นระหว่างหน้าและโฆษณาที่มีการให้รางวัลจะใช้รูปแบบโฆษณาแบบเต็มหน้าจอทั่วไปเดียวกันเพื่อให้สอดคล้องกันมากขึ้น API โฆษณาแบบเต็มหน้าจอใหม่เหล่านี้มีความแตกต่างจาก API โฆษณาแบบเต็มหน้าจอเวอร์ชัน 7 ที่สำคัญ 2 อย่าง ดังนี้

  1. เมธอดคลาสแบบคงที่ load

    แนวทางก่อนหน้าในการโหลด/แสดงโฆษณาแบบเต็มหน้าจอมีดังนี้

    1. สร้างอินสแตนซ์ออบเจ็กต์โฆษณาและเก็บข้อมูลอ้างอิงไว้
    2. มอบหมายผู้รับมอบสิทธิ์ที่จัดการการโหลดและแสดงการเรียกกลับ
    3. โหลดโฆษณา
    4. ตรวจสอบว่าโฆษณาโหลดโดยใช้ isReady หรือไม่
    5. แสดงโฆษณา

    ในเวอร์ชัน 8 แนวทางนี้จะเปลี่ยนแปลงเล็กน้อย การเรียกกลับของโหลดไม่ได้เป็นส่วนหนึ่งของผู้รับมอบสิทธิ์อีกต่อไป แต่ระบบจะส่งค่าไปยังเมธอด load ในฐานะตัวแฮนเดิลการดําเนินการเสร็จสมบูรณ์แทน

    1. เรียกใช้เมธอดการโหลดแบบคงที่ในคลาสโฆษณาและระบุตัวแฮนเดิลการโหลดเสร็จสมบูรณ์
    2. ในคอลแบ็กการโหลดเสร็จสมบูรณ์ ให้เก็บการอ้างอิงถึงโฆษณาที่โหลดซึ่งแสดงผล
    3. กำหนดผู้รับมอบสิทธิ์ที่จัดการการเรียกกลับของรายการ
    4. แสดงโฆษณา

    แนวทางใหม่นี้มีข้อดีดังนี้

    • คุณจะไม่มีข้อมูลอ้างอิงถึงโฆษณาที่ไม่ได้โหลด
    • คุณไม่จำเป็นต้องถือออบเจ็กต์โฆษณาไว้ขณะที่กําลังโหลด
  2. เหตุการณ์โฆษณาที่สอดคล้องกัน

    ประเภทของกิจกรรม API ที่มีอยู่ v8 API
    เหตุการณ์การโหลด GADInterstitialDelegate หรือ GADRewardedAdDelegate GAMInterstitialAdLoadCompletionHandler หรือ GADRewardedAdLoadCompletionHandler
    กิจกรรมการนำเสนอ GADFullScreenContentDelegate

    ก่อนหน้านี้ หากต้องการฟังเหตุการณ์โฆษณา คุณจะต้องลงทะเบียนคลาสที่ใช้โปรโตคอล GADInterstitialDelegate กับพร็อพเพอร์ตี้ตัวแทนของโฆษณาคั่นระหว่างหน้า หรือลงทะเบียนคลาสที่ใช้โปรโตคอล GADRewardedAdDelegate กับพร็อพเพอร์ตี้ตัวแทนของโฆษณาที่มีการให้รางวัล ทั้งนี้ขึ้นอยู่กับรูปแบบที่คุณใช้ โดยผู้รับมอบสิทธิ์รายนี้มีเมธอดที่เกี่ยวข้องกับทั้งวงจรการโหลดและการแสดงโฆษณา

    ในเวอร์ชัน 8 เหตุการณ์การโหลดและการแสดงผลจะแยกกัน ตอนนี้คุณลงทะเบียน GADFullScreenContentDelegate ได้ตลอดเวลาก่อนที่จะแสดงโฆษณาแทนที่จะต้องตั้งค่าตัวแทนเพียงรายเดียวก่อนที่จะโหลดโฆษณา เหตุการณ์การโหลดโฆษณาซึ่งเจาะจงสำหรับแต่ละรูปแบบจะย้ายไปยังตัวแฮนเดิลการโหลดที่เสร็จสมบูรณ์รายการเดียวที่ส่งในเมธอดการโหลด

โฆษณาคั่นระหว่างหน้า

โหลดโฆษณา

ข้อมูลโค้ดด้านล่างแสดงวิธีโหลดโฆษณาคั่นระหว่างหน้าและรอเหตุการณ์เมื่อโฆษณาโหลดสําเร็จหรือไม่สําเร็จ

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

โฆษณาแบบดิสเพลย์

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

เหตุการณ์โฆษณาของงานนำเสนอ

ข้อมูลโค้ดด้านล่างแสดงวิธีจัดการการเรียกกลับเมื่อโฆษณาแสดง (สำเร็จหรือไม่สําเร็จ) และเมื่อปิดโฆษณา

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

ได้รับรางวัลแล้ว

โหลดโฆษณา

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

แสดงโฆษณาและจัดการรางวัล

โฆษณาที่มีการให้รางวัลกำหนดให้คุณจัดการเหตุการณ์เมื่อผู้ใช้ได้รับรางวัล เมื่อใช้ GADRewardedAd API เวอร์ชัน 7 คุณจะติดตั้งใช้งาน rewardedAd:userDidEarnReward: เป็นส่วนหนึ่งของโปรโตคอล GADRewardedAdDelegate สําหรับเวอร์ชัน 8 คุณต้องใช้ GADUserDidEarnRewardHandler เพื่อแสดงโฆษณา

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

เหตุการณ์โฆษณาของงานนำเสนอ

เมื่อใช้ GADRewardedAd API คุณจะส่ง GADRewardedAdDelegate ไปยังเมธอดที่แสดงโฆษณา เมื่อใช้ GADRewardedAd API คุณจะตั้งค่า GADFullscreenContentDelegate เป็นพร็อพเพอร์ตี้ในโฆษณาก่อนที่จะแสดงโฆษณา

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

การนำ GADRewardedBasedVideoAd API เดิมออก

เราเปิดตัว API เวอร์ชันใหม่ GADRewardedAd ไปเมื่อเดือนมีนาคม 2019 และ API ดังกล่าวเป็น API แบบให้รางวัลที่ได้รับความนิยมมาเป็นเวลากว่า 18 เดือน โดยมีการปรับปรุงมากกว่าGADRewardedBasedVideoAd API รุ่นเดิม รวมถึงความสามารถในการโหลดโฆษณาที่มีการให้รางวัลได้มากกว่า 1 รายการพร้อมกัน

ระบบจะนำ GADRewardedBasedVideoAd API เดิมออกใน SDK เวอร์ชัน 8.0.0

การเลิกใช้งานแบนเนอร์อัจฉริยะเพื่อหันมาใช้แบนเนอร์แบบปรับขนาดได้

เราเลิกใช้งานโฆษณาแบนเนอร์อัจฉริยะแล้วเพื่อหันมาใช้โฆษณาแบนเนอร์แบบปรับขนาดได้แทน แบนเนอร์แบบปรับขนาดได้มีประสิทธิภาพเหนือกว่าและมีความยืดหยุ่นมากขึ้นในการกำหนดความกว้างของโฆษณา หากต้องการใช้แบนเนอร์แบบเต็มความกว้างต่อไป คุณยังคงใช้แบนเนอร์แบบปรับขนาดได้ได้ตามตัวอย่างข้อมูลโค้ดต่อไปนี้

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

ออกจากการนำการโทรกลับของใบสมัครออก

ระบบได้นําwillLeaveApplicationการเรียกกลับสําหรับโฆษณาทุกรูปแบบออกแล้วเพื่อใช้วิธีapplicationDidEnterBackground:และsceneDidEnterBackground:แทน การใช้ API ระดับระบบปฏิบัติการจะแจ้งให้คุณทราบทุกครั้งที่ผู้ใช้ออกจากแอป ไม่ว่าจะเกิดจากการโต้ตอบกับโฆษณาหรือไม่ก็ตาม

โปรดทราบว่าการเรียกกลับ willLeaveApplication ไม่ได้มีไว้เพื่อเป็นตัวแฮนเดิลการคลิกโฆษณา และการใช้การเรียกกลับนี้เพื่อรายงานการคลิกไม่ได้สร้างเมตริกที่ถูกต้อง เช่น การคลิกไอคอน AdChoices ที่เปิดเบราว์เซอร์ภายนอกจะเรียกใช้การเรียกกลับ แต่ไม่นับเป็นการคลิก

การเปลี่ยนชื่อชั้นเรียน

ตารางด้านล่างแสดงชื่อชั้นเรียนที่เปลี่ยนแปลงหรือถูกนำออกในเวอร์ชัน 8 โดยสรุป

  • เปลี่ยนชื่อชั้นเรียนทั้งหมดที่เกี่ยวข้องกับ GADUnifiedNativeAd เป็น GADNativeAd แล้ว
  • มีการนำ GADRewardBasedVideoAd, GADNativeExpressAdView และ GADInstreamAd ออกแล้ว
  • คลาสทั้งหมดที่มีคำนำหน้า DFP ได้รับการแทนที่ด้วยคำนำหน้า GAM แล้ว
คลาส v7.68.0 คลาส 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 นำออกแล้ว
GADInterstitial GADInterstitialAd
GADNativeExpressAdView นำออกแล้ว
GADRewardBasedVideoAd นำออกแล้ว
GADInstreamAd นำออกแล้ว
GADInstreamAdView นำออกแล้ว

วิธีการที่นําออก/แทนที่

ตารางด้านล่างแสดงการเปลี่ยนแปลงที่เฉพาะเจาะจงในเวอร์ชัน 8 โดยสรุป

  • ระบบได้นำเมธอดและพร็อพเพอร์ตี้ที่เลิกใช้งานไปแล้วก่อนหน้านี้ออกแล้ว
  • -willLeaveApplication: มีการนำเมธอด "delegate" ออกสำหรับทุกรูปแบบ
  • ชื่อคลาสเครือข่ายโฆษณาได้ย้ายไปยังพร็อพเพอร์ตี้ GADResponseInfo แล้ว
  • ระบบได้ย้ายตัวระบุอุปกรณ์ทดสอบไปยังพร็อพเพอร์ตี้ GADRequestConfiguration แล้ว
คลาส v7.68.0 API เวอร์ชัน 7.68.0 API v8.0.0 หมายเหตุ
GADMobileAds +configureWithApplicationID: -startWithCompletionHandler: ตอนนี้รหัสแอปได้รับการตั้งค่าใน Info.plist แล้ว
+disableAutomatedInAppPurchaseReporting -disableAutomatedInAppPurchaseReporting
+disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers พร็อพเพอร์ตี้ testDeviceIdentifiers มีผลกับคำขอโฆษณาทั้งหมด ขณะที่พร็อพเพอร์ตี้ testDevices เดิมจะตั้งค่าต่อคำขอ
gender นำออกแล้ว
วันเกิด นำออกแล้ว
+sdkVersion GADMobileAds.sharedInstance.sdkVersion
-setBirthdayWithMonth:day:year: นำออกแล้ว
-setLocationWithDescription: -setLocationWithLatitude:longitude:accuracy:
-tagForChildDirectedTreatment: [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment]
GADErrorCode kGADError* GADError* ระบบจะนำคำนำหน้า k ออกจากค่าคงที่ของรหัสข้อผิดพลาดทั้งหมด
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate นำออกแล้ว
mediatedAdView นำออกแล้ว
adNetworkClassName responseInfo.adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSizes:
DFPBannerViewOptions -adSizeDelegate นำออกแล้ว
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewWillPresentScreen: -bannerViewWillPresentScreen:
-adViewWillDismissScreen: -bannerViewWillDismissScreen:
-adViewDidDismissScreen: -bannerViewDidDismissScreen:
-adViewWillLeaveApplication: นำออกแล้ว
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate นำออกแล้ว
isReady นำออกแล้ว ให้ใช้ canPresentFromRootViewController:error: แทน
hasBeenUsed นำออกแล้ว
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialWillLeaveApplication: นำออกแล้ว
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName