نقل بيانات حِزم تطوير البرامج (SDK)

تتناول هذه الصفحة عمليات نقل البيانات للإصدارات الحالية والسابقة من حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" لنظام التشغيل iOS. ومن المتوقَّع أن يتم طرح الإصدار 11.0.0 في كانون الثاني (يناير) 2024.

نقل البيانات من الإصدار 10 إلى الإصدار 11 من حزمة تطوير البرامج (SDK)

الحد الأدنى لهدف النشر

تمت زيادة الحد الأدنى لهدف النشر إلى الإصدار 12 من نظام التشغيل iOS.

الحد الأدنى لإصدار Xcode

تمت زيادة الحد الأدنى لإصدار Xcode المتوافق إلى 15.1.

توقُّف عرض الإعلانات على الإصدار 12 من نظام التشغيل iOS

إنّ الإصدار 11.0.0 من حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" يعرض الإعلانات فقط على الأجهزة التي تعمل بالإصدار 13 من نظام التشغيل iOS أو الإصدارات الأحدث.

تمت إزالة تبعية GoogleAppMeasurement.

في الإصدار 11.0.0، تمت إزالة الاعتماد على GoogleAppMeasurement. في أوائل عام 2024، سيتم إيقاف هذه الاعتمادية التي أدت إلى تفعيل ميزة تبديل مقاييس سلوك المستخدمين في AdMob. لمواصلة جمع مقاييس سلوك المستخدِمين في AdMob، عليك ربط تطبيقك على AdMob بمنصّة Firebase ودمج حزمة تطوير البرامج (SDK) لإحصاءات Google لبرنامج Firebase في تطبيقك.

التغييرات على عرض الإعلان بملء الشاشة

ستؤثّر التغييرات التالية في أشكال الإعلانات المختلفة:

  • إعلان على شاشة فتح التطبيق
  • إعلان بيني
  • تم منح المكافأة
  • الإعلان البيني بمكافأة

معلَمة وحدة التحكّم في طريقة العرض في -canPresentFromRootViewController:error: و-presentFromRootViewController: قيمة فارغة. إذا تم تمرير صفر، يتم عرض الإعلان من أعلى وحدة تحكم في العرض في التسلسل الهرمي لوحدة التحكم في طرق العرض.

تمّت إزالة الطرق

تمت إزالة الطرق التالية.

النوع v11.0.0 الطريقة Notes
إعلان 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 الموقع Notes
GADMediationAdConfiguration hasUserLocation لا يوجد بديل.
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment يمكنك استخدام GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment بدلاً منها.
GADResponseInfo adNetworkClassName يمكنك استخدام adNetworkClassName من loadedAdNetworkResponseInfo بدلاً من ذلك.

تمت إزالة GADAdFormat غير معروف

تمت إزالة "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 واجهة المستخدم.

نقل البيانات من الإصدار 9 إلى الإصدار 10

توقّف عرض الإعلانات على نظام التشغيل iOS 11

يعرض الإصدار 10.0.0 من حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" الإعلانات فقط على الأجهزة التي تعمل بنظام التشغيل iOS 12 والإصدارات الأحدث.

لن تؤدي الترقية إلى الإصدار 10.0.0 من حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" إلى تعطُّل تطبيقك على الأجهزة التي تعمل بنظامَي التشغيل iOS 11 وiOS 10، ومع ذلك، لن يتمّ عرض أيّ إعلانات على تلك الأجهزة.

لم يعُد من الممكن استخدام ميزة "إنشاء البيانات باستخدام رمز بت"

أصبح إيقاف رمز بت في التطبيقات المتوافقة مع الأجهزة الجوّالة مطلوبًا الآن لدمج حزمة "SDK لإعلانات Google على الأجهزة الجوّالة".

تمت إزالة الأنواع.

Type Notes
GADGender لا يوجد بديل.
GADMRewardBasedVideoAdNetworkAdapterProtocol لقد توقّفت جميع محوِّلات التوسّط بمكافأة المدرَجة في قائمة Select Networks عن استخدام هذه البروتوكولات لمدة تزيد عن سنة. استخدِم GADMediationAdapter للتوسّط والأحداث المخصّصة.
GADMRewardBasedVideoAdNetworkConnectorProtocol

تمت إزالة المواقع

تمت إزالة السمات التالية بدون بديل.

الفئة v10.0.0 الموقع
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

نقل البيانات من الإصدار 8 إلى الإصدار 9

توقّف عرض الإعلانات على نظام التشغيل iOS 10

الحد الأدنى لإصدار نظام التشغيل iOS الذي يتوافق مع الإصدار 9.0.0 من حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة هو iOS 11.

لن تؤدي الترقية إلى الإصدار 9.0.0 من حزمة SDK لإعلانات Google على الأجهزة الجوّالة إلى تعطُّل تطبيقك على الأجهزة التي تعمل بنظام التشغيل iOS 10، ومع ذلك، لن يتم عرض أي إعلانات على تلك الأجهزة.

تنفيذ أكثر صرامة لعناصر التحكم في شريط الحالة

بدءًا من الإصدار 9.0.0، عند تقديم إعلانات بتنسيق ملء الشاشة، يجب أن يضمن تطبيقك قدرة الإعلانات على التحكم في طريقة عرض شريط الحالة. ستظهر لك رسالة خطأ في السجلّات في حال تعذُّر إجراء ذلك.

بناءً على التخطيط المحدد لوحدات التحكم في طريقة العرض في تطبيقك، قد لا تحتاج إلى إجراء أي تغييرات لضمان ذلك. فكّر في ما إذا كنت بحاجة إلى ضبط السمة childViewControllerForStatusBarHidden على rootViewController لإعلانك.

إعادة تسمية adDidPresentFullscreenContent: إلى adwillPresentFullscreenContent:

ما مِن تغيير في السلوك. يتم استدعاء طريقة التفويض قبل عرض الإعلان مباشرةً، حتى يعكس اسم الطريقة الجديدة وظائفه بشكل أفضل.

إزالة واجهة برمجة تطبيقات إعداد الموقع الجغرافي على GADRequest

تم حذف - (void)setLocationWithLatitude:longitude:accuracy: من GADRequest نظرًا لأن Google لا تستخدم بيانات الموقع الجغرافي لاستهداف الإعلانات. استخدِم واجهات برمجة التطبيقات التابعة لجهات خارجية لتوفير المعلومات لشبكات المواقع الإعلانية التابعة لجهات خارجية إذا لزم الأمر.

إيقاف واجهات الأحداث المخصَّصة نهائيًا

تمكّن الأحداث المخصّصة الناشرين الذين يستخدمون AdMob التوسّط من إضافة توسّط العرض الإعلاني بدون انقطاع لشبكة إعلانات ليست من شبكات الإعلانات المتوافقة.

تم إيقاف جميع بروتوكولات الأحداث المخصّصة نهائيًا. بدلاً من ذلك، استخدِم البروتوكولَين الحاليَين GADMediationAdapter وGADMediationAdEventDelegate لتحقيق الوظائف نفسها. يساعد هذا التغيير في زيادة الوضوح ويتيح لك إنشاء أحداث مخصّصة للإعلانات التي تضم مكافآت والإعلانات البينية التي لم تكن متوفّرة في السابق.

واجهات برمجة التطبيقات

يسرد الجدول التالي واجهات برمجة التطبيقات المقابلة لمحوّل التوسّط مع واجهات برمجة التطبيقات للأحداث المخصّصة التي يجب استخدامها بدءًا من الإصدار 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
GADCustomEventBanner الإدارة
GADCustomEventInterstitial فواتير
GADCustomEventNativeAdدور
GADMediationAdEventDelegate إعلان GADMediation
-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 كبديل.
واجهات برمجة التطبيقات للشراء داخل التطبيق في GoogleMobileAds تمت إزالة inAppPurchase واجهات برمجة تطبيقات في GoogleMobileAds.

نقل البيانات من الإصدار 7 إلى الإصدار 8

يقدّم الإصدار 8.0.0 من حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة بعض التغييرات الرئيسية، بالإضافة إلى بعض عمليات إعادة التسمية وإزالة واجهات برمجة التطبيقات.

تحديثات واجهة برمجة التطبيقات لتنسيق ملء الشاشة

بدءًا من الإصدار 8.0.0، تتشارك الإعلانات البينية والإعلانات التي تضم مكافأة نمطًا عامًا من الإعلانات بملء الشاشة لتحقيق المزيد من الاتساق. تتميز واجهات برمجة التطبيقات الجديدة للإعلانات بملء الشاشة بنوعين رئيسيين عن الإصدار 7 من واجهات برمجة التطبيقات للإعلانات بملء الشاشة:

  1. طريقة الفئة الثابتة load:

    في ما يلي الأسلوب السابق لتحميل/عرض إعلان ملء الشاشة:

    1. أنشئ مثيلاً لكائن الإعلان واحتفظ بإشارة إليه.
    2. يمكنك تحديد مفوَّض يتولّى تحميل عمليات الردّ على المكالمات وعرضها.
    3. تحميل إعلان
    4. تحقَّق من تحميل الإعلان باستخدام "isReady".
    5. اعرض الإعلان.

    في الإصدار 8، يتغير النهج قليلاً. لم يعد تحميل استدعاءات الاتصال جزءًا من المفوَّض. وبدلاً من ذلك، يتم تمريرها إلى الإجراء load كمعالج إكمال:

    1. عليك استدعاء طريقة تحميل ثابتة في فئة الإعلان وتوفير معالج لإكمال التحميل.
    2. في استدعاء إكمال التحميل، احتفظ بمرجع للإعلان المحمَّل الذي تم عرضه.
    3. يمكنك تخصيص مفوَّض يتولّى عرض عمليات معاودة الاتصال.
    4. اعرض الإعلان.

    يوفر الأسلوب الجديد المزايا التالية:

    • ولن يكون لديك على الإطلاق مرجع إلى إعلان لم يتم تحميله.
    • ولا تحتاج إلى الاحتفاظ بكائن الإعلان أثناء تحميله.
  2. أحداث إعلانات متّسقة:

    نوع الفعالية واجهة برمجة التطبيقات الحالية v8 API
    تحميل الأحداث السمة 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;
}

إعلان صوري والتعامل مع المكافآت

تتطلب الإعلانات التي تضم مكافآت التعامل مع الحدث عندما يربح المستخدم مكافأة. في الإصدار 7 من واجهة برمجة التطبيقات GADRewardedAd، يتم تنفيذ 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، يمكنك ضبط 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 القديمة

تم طرح GADRewardedAd واجهة برمجة التطبيقات الأحدث لأول مرة في آذار (مارس) 2019، وظلت واجهة برمجة التطبيقات المفضّلة التي تضم مكافأة لمدة تزيد عن 18 شهرًا. ويشتمل هذا الإصدار على المزيد من التحسينات مقارنةً بواجهة برمجة تطبيقات GADRewardedBasedVideoAd القديمة، بما في ذلك إمكانية تحميل أكثر من إعلان واحد بمكافأة في الوقت نفسه.

تمّت إزالة واجهة برمجة التطبيقات GADRewardedBasedVideoAd القديمة في الإصدار 8.0.0 من حزمة تطوير البرامج (SDK).

إيقاف البانر الذكي لصالح إعلان البانر التكيُّفي

تم إيقاف إعلانات بانر الذكية لصالح إعلانات بانر التكيُّفية. توفّر "إعلانات البانر التكيُّفية" أداءً متميّزًا ومرونة أكبر في تحديد عرض الإعلان. إذا كنت تفضّل مواصلة استخدام إعلانات البانر ذات العرض الكامل، لا يزال بإمكانك إجراء ذلك باستخدام إعلانات البانر التكيُّفية، كما هو موضّح في مقتطف الرمز التالي:

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:. يُعلِمك استخدام واجهات برمجة التطبيقات على مستوى نظام التشغيل عندما يغادر المستخدمون تطبيقك، بغض النظر عمّا إذا كان ذلك بسبب تفاعل مع الإعلان أم لا.

تجدر الإشارة إلى أنّ معاودة الاتصال willLeaveApplication لم تكن تهدف أبدًا إلى أن تكون معالجًا للنقرات على الإعلانات، وأنّ الاعتماد على معاودة الاتصال هذه للإبلاغ عن النقرات لم يؤدِ إلى إنشاء مقياس دقيق. على سبيل المثال، إنّ النقرة على رمز "خيارات الإعلان" التي أطلقت متصفحًا خارجيًا استدعت معاودة الاتصال ولكنها لم تحتسب نقرة.

إعادة تسمية الصف

يسرد الجدول أدناه أسماء فئات محددة تم تغييرها أو إزالتها في الإصدار 8. باختصار:

  • تمت إعادة تسمية جميع الصفوف المرتبطة بالصف "GADUnifiedNativeAd" لتصبح "GADNativeAd".
  • تمت إزالة GADRewardBasedVideoAd وGADNativeExpressAdView وGADInstreamAd.
  • تم استبدال جميع الصفوف التي تستخدم البادئة DFP بالبادئة GAM.
الفئة v7.68.0 الفئة v8.0.0
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial إعلان بيني في "مدير إعلانات Google"
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
إعلان GADUnifiedNativeAd إعلان GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomTemplateAd GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase تمت إزالته
GADInterstitial إعلان بيني GAD
GADNativeExpressAdView تمت إزالته
إعلان فيديو يستند إلى GADRewardBased تمت إزالته
إعلان GADInstream تمت إزالته
GADInstreamAdView تمت إزالته

طرق تمت إزالتها/استبدالها

يسرد الجدول التالي التغييرات المحدَّدة في الإصدار 8. باختصار:

  • وتمّت إزالة الطرق والخصائص المتوقّفة سابقًا.
  • تمت إزالة -willLeaveApplication: طريقة تفويض لجميع التنسيقات.
  • تم نقل اسم فئة شبكة الإعلانات إلى السمة GADResponseInfo.
  • تم نقل معرّف جهاز الاختبار إلى السمة GADRequestConfiguration.
الفئة v7.68.0 الإصدار 7.68.0 من واجهة برمجة التطبيقات الإصدار 8.0.0 من واجهة برمجة التطبيقات Notes
إعلانات GADMobileAds +ConfigureWithApplicationID: -startWithCompleteHandler: تم ضبط رقم تعريف التطبيق الآن في Info.plist.
+disableAutoAutoInAppPurchaseReporting -disableAutoAutoInAppPurchaseReporting
+disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers تنطبق الخاصية testDeviceIds على جميع طلبات الإعلانات، في حين أنّه تم ضبط سمة 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 -setصالحAdSizesWithSizes: -setvalidAdSizes:
DFPBannerViewOptions -adSizeSize تمت إزالته
GADBannerViewDelegate -adViewDidSingleAd: -bannerViewDidReceivedAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewwillPresentScreen: -bannerViewwillPresentScreen:
-adViewwillSeeScreen: -bannerViewwill المحدَّدScreen:
-adViewDidPauseScreen: -bannerViewDidPauseScreen:
-adViewwillمغادرةApplication: تمت إزالته
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate تمت إزالته
isReady تمت إزالته استخدِم canPresentFromRootViewController:error: بدلاً منه.
hasBeenUsed تمت إزالته
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName ResponseInfo.adNetworkClassName
-interstitialwillRemoveApplication: تمت إزالته
إعلان GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName ResponseInfo.adNetworkClassName