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

หน้านี้จะพูดถึงการย้ายข้อมูลของ Google Mobile Ads SDK สำหรับ iOS เวอร์ชันปัจจุบันและก่อนหน้า เวอร์ชัน 11.0.0 คาดว่าจะเปิดตัวในเดือนมกราคม 2024

ย้ายข้อมูลจาก SDK เวอร์ชัน v10 ไปยัง v11

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

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

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

เพิ่ม Xcode เวอร์ชันต่ำสุดที่รองรับเป็น 15.1

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

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

นำทรัพยากร Dependency ของ GoogleAppMeasurement ออกแล้ว

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

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

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

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

พารามิเตอร์ตัวควบคุมมุมมองใน -canPresentFromRootViewController:error: และ -presentFromRootViewController: เป็นค่าว่างได้ หากค่าผ่าน nil จะแสดงจากตัวควบคุมมุมมองระดับบนสุดในลำดับชั้นของตัวควบคุมข้อมูลพร็อพเพอร์ตี้

นำเมธอดออกแล้ว

ระบบจะนำวิธีการต่อไปนี้ออก

ประเภท v11.0.0 วิธีการ Notes
โฆษณา GADAppOpen 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 พร็อพเพอร์ตี้ Notes
GADMediationAdConfiguration hasUserLocation ไม่มีการทดแทน
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment โปรดใช้ GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment แทน
GADResponseInfo adNetworkClassName ใช้ adNetworkClassName จาก loadedAdNetworkResponseInfo แทน

นำ GADAdFormatUnknown ออกแล้ว

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

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

เวอร์ชัน 11.0.0 จะนำ sdkVersion ออก หากต้องการบันทึกเวอร์ชัน SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google ให้ใช้ 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
  • อุปกรณ์คือเครื่องมือจำลอง
  • อุปกรณ์ได้รับการประกาศอย่างชัดเจนว่าเป็นอุปกรณ์ทดสอบใน AdMob UI

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

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

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

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

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

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

นำประเภทออกแล้ว

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

นำพร็อพเพอร์ตี้ออกแล้ว

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

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

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

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

SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google เวอร์ชัน 9.0.0 รองรับ iOS ขั้นต่ำคือ iOS 11

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

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

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

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

เปลี่ยนชื่อ adDidOfferFullScreenContent: เป็น adwillงานนำเสนอFullScreenContent

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

นำ API การตั้งค่าตำแหน่งออกจาก GADRequest

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

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

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

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

API

ตารางด้านล่างแสดง API ของอะแดปเตอร์สื่อกลางที่สอดคล้องกับ API เหตุการณ์ที่กำหนดเอง ซึ่งควรใช้ตั้งแต่เวอร์ชัน 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 โฆษณาสื่อกลาง
-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 แทน
GAMRequest kGAMSimulatorID ใน GAMRequest เลิกใช้งานแล้ว ใช้ GADSimulatorID ใน GADRequestConfiguration แทน
GADCustomNativeAd mediaView ใน GADCustomNativeAd เลิกใช้งานแล้ว โปรดใช้ mediaContent แทน
API การซื้อในแอปใน GoogleMobileAds นำ API inAppPurchase ใน GoogleMobileAds ออกแล้ว

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

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

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

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

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

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

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

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

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

    แนวทางใหม่นี้ให้ประโยชน์ดังนี้

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

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

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

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

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

โหลดโฆษณา

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

v7

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADInterstitialDelegate {

  var interstitial: GADInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()
    interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/44118910")
    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/44118910"];
  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/44118910"
                              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;
  }];
}

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

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 = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/44118910")
  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/44118910"];
  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/44118910"
                              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.");
}

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

โหลดโฆษณา

v7

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADRewardedAdDelegate {
  /// The rewarded ad.
  var rewardedAd: GADRewardedAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313")
    rewardedAd.delegate = self
    rewardedAd?.load(GADRequest()) { error in
      if let error = error {
        print("Rewarded ad failed to load with error: \(error.localizedDescription)")
      } else {
        print("Rewarded ad loaded.")
      }
    }
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.rewardedAd = [[GADRewardedAd alloc]
      initWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"];
  self.rewardedAd.delegate = self;
  GADRequest *request = [GADRequest request];
  [self.rewardedAd loadRequest:request completionHandler:^(GADRequestError * _Nullable error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
    } else {
      NSLog(@"Rewarded ad loaded.");
    }
  }];
}

v8

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {
  /// The rewarded ad.
  var rewardedAd: GADRewardedAd?

  override func viewDidLoad() {
  super.viewDidLoad()
  let request = GADRequest()
  GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136",
                          request: request, completionHandler: { (ad, error) in
                            if let error = error {
                              print("Rewarded ad failed to load with error: \(error.localizedDescription)")
                              return
                            }
                            self.rewardedAd = ad
                            self.rewardedAd?.fullScreenContentDelegate = self
                          }
  )
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  GADRequest *request = [GADRequest request];
  [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"
                          request:request
                completionHandler:^(GADRewardedAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
      return;
    }
    self.rewardedAd = ad;
    NSLog(@"Rewarded ad loaded.");
    self.rewardedAd.fullScreenContentDelegate = self;
}

โฆษณา Display และรางวัลในการจัดการ

โฆษณาที่มีการให้รางวัลกำหนดให้คุณจัดการกิจกรรมเมื่อผู้ใช้ได้รับรางวัล เมื่อใช้ 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 = 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.");
}

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

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

เราจะนํา API GADRewardedBasedVideoAd เดิมออกจาก 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 Callback สำหรับรูปแบบโฆษณาทั้งหมดออกเพื่อใช้เมธอด applicationDidEnterBackground: และ sceneDidEnterBackground: แทน การใช้ API ระดับระบบปฏิบัติการจะแจ้งให้คุณทราบทุกครั้งที่ผู้ใช้ออกจากแอป ไม่ว่าจะเกิดจากการโต้ตอบกับโฆษณาหรือไม่ก็ตาม

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

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

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

  • ชั้นเรียนทั้งหมดที่เกี่ยวข้องกับ GADUnifiedNativeAd เปลี่ยนชื่อเป็น GADNativeAd แล้ว
  • นำ GADRewardBasedVideoAd, GADNativeExpressAdView และ GADInstreamAd ออกแล้ว
  • ระบบได้แทนที่คลาสทั้งหมดที่มีคำนำหน้า DFP ด้วยคำนำหน้า GAM แล้ว
คลาส v7.68.0 คลาส v8.0.0
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial โฆษณาคั่นระหว่างหน้าใน GAMInterstitial
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
GADUnifiedNativeAd GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomTemplateAd GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase นำออกแล้ว
GADInterstitial โฆษณาคั่นระหว่างหน้า GAD
GADNativeExpressAdView นำออกแล้ว
โฆษณาวิดีโอตามรางวัล GADReward นำออกแล้ว
โฆษณาแบบสตรีมใน GAD นำออกแล้ว
GADInstreamAdView นำออกแล้ว

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

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

  • ระบบได้นำเมธอดและพร็อพเพอร์ตี้ที่เลิกใช้งานไปก่อนหน้านี้ออกแล้ว
  • นำวิธีการมอบสิทธิ์ -willLeaveApplication: รายการสำหรับทุกรูปแบบออกแล้ว
  • ย้ายชื่อคลาสเครือข่ายโฆษณาไปยังพร็อพเพอร์ตี้ GADResponseInfo แล้ว
  • ย้ายตัวระบุอุปกรณ์ทดสอบไปยังพร็อพเพอร์ตี้ GADRequestConfiguration แล้ว
คลาส v7.68.0 API v7.68.0 API v8.0.0 Notes
โฆษณาบนอุปกรณ์เคลื่อนที่ GAD +ConfigureWithApplicationID: -startWithCompletionHandler: รหัสแอปก็ตั้งค่าใน Info.plist แล้ว
+disableAutomatedInAppการรายงานการซื้อ -disableAutomatedInAppการซื้อการรายงาน
+ปิดใช้SDKCrashReporting -ปิดใช้SDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers พร็อพเพอร์ตี้ testDeviceIdentifiers มีผลกับคำขอโฆษณาทั้งหมด ส่วนพร็อพเพอร์ตี้ testDevice แบบเก่าตั้งค่าไว้ตามคำขอ
gender นำออกแล้ว
วันเกิด นำออกแล้ว
+sdkVersion GADMobileAds.sharedInstance.sdkVersion
-setBirthdayWithMonth:day:year: นำออกแล้ว
-setLocationWithDescription: -setLocationWithLatitude:longitude:accuracy:
-tagForChildDirectedTreatment: [แท็ก GADMobileAds.sharedInstance.requestConfiguration ForChildDirectedTreatment]
GADErrorCode kGADError* GADError* คำนำหน้า k ถูกตัดออกจากค่าคงที่รหัสข้อผิดพลาดทั้งหมด
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate นำออกแล้ว
mediatedAdView นำออกแล้ว
adNetworkClassName ResponseInfo.adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSizes:
DFPBannerViewOptions -adSizeDelegate นำออกแล้ว
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewwillงานนำเสนอScreen: -bannerView WillpresentScreen:
-adViewwillReachScreen: -bannerView WillCloseScreen:
-adViewDidCancelScreen: -bannerView DidReturnScreen:
-adViewwillReleaseApplication: นำออกแล้ว
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate นำออกแล้ว
isReady นำออกแล้ว ใช้ canpresentFromRootViewController:error: แทน
hasBeenUsed นำออกแล้ว
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName ResponseInfo.adNetworkClassName
-interstitial WillExitApplication: นำออกแล้ว
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName ResponseInfo.adNetworkClassName