الأحداث المخصّصة للإعلانات المدمجة مع المحتوى

المتطلبات الأساسية

أكمِل إعداد الأحداث المخصَّصة.

طلب إعلان مدمج مع المحتوى

عند الوصول إلى عنصر الحدث المخصّص في سلسلة توسّط العرض الإعلاني بدون انقطاع، يتم استدعاء طريقة loadNativeAd:adConfiguration:completionHandler: في اسم الفئة الذي قدمته عند إنشاء صف . وفي هذه الحالة، تلك الطريقة هي في SampleCustomEvent، والتي تستدعي بعد ذلك طريقة loadNativeAd:adConfiguration:completionHandler: في SampleCustomEventNative

لطلب إعلان مدمج مع المحتوى، يجب إنشاء أو تعديل فئة لتنفيذ "GADMediationAdapter" وloadNativeAd:adConfiguration:completionHandler:" في حال حذف توجد فئة تمتد على GADMediationAdapter، يُرجى تنفيذ loadNativeAd:adConfiguration:completionHandler: هناك. بالإضافة إلى ذلك، أنشئ فئة جديدة لتنفيذ GADMediationNativeAd.

في مثال الحدث المخصّص ينفذ SampleCustomEvent واجهة GADMediationAdapter ثم يفوض SampleCustomEventNative

Swift

import GoogleMobileAds

class SampleCustomEvent: NSObject, GADMediationAdapter {

  fileprivate var nativeAd: SampleCustomEventNativeAd?

  func loadNativeAd(
    for adConfiguration: GADMediationNativeAdConfiguration,
    completionHandler: @escaping GADMediationNativeAdLoadCompletionHandler
  ) {
    self.nativeAd = SampleCustomEventNativeAd()
    self.nativeAd?.loadNativeAd(
      for: adConfiguration, completionHandler: completionHandler)
  }
}

Objective-C

#import "SampleCustomEvent.h"

@implementation SampleCustomEvent

SampleCustomEventNativeAd *sampleNativeAd;

- (void)loadNativeAdForAdConfiguration:
            (GADMediationNativeAdConfiguration *)adConfiguration
                     completionHandler:
                         (GADMediationNativeAdLoadCompletionHandler)
                             completionHandler {
  sampleNative = [[SampleCustomEventNativeAd alloc] init];
  [sampleNative loadNativeAdForAdConfiguration:adConfiguration
                             completionHandler:completionHandler];
}

يكون SampleCustomEventNative مسؤولاً عن المهام التالية:

  • جارٍ تحميل الإعلان المدمج مع المحتوى

  • جارٍ تنفيذ بروتوكول GADMediationNativeAd.

  • تلقّي استدعاءات أحداث الإعلانات وإعداد تقارير عنها إلى حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"

المعلمة الاختيارية المحددة في واجهة مستخدم "مدير الإعلانات" هي مضمّنة في إعدادات الإعلان. يمكن الوصول إلى المعلمة من خلال adConfiguration.credentials.settings[@"parameter"] هذه المعلمة تمثّل عادةً معرّف وحدة إعلانية تطلبه حزمة تطوير البرامج (SDK) لشبكة الإعلانات عندما إنشاء مثيل لعنصر إعلان

Swift

class SampleCustomEventNativeAd: NSObject, GADMediationNativeAd {
  /// The Sample Ad Network native ad.
  var nativeAd: SampleNativeAd?

  /// The ad event delegate to forward ad rendering events to the Google Mobile
  /// Ads SDK.
  var delegate: GADMediationNativeAdEventDelegate?

  /// Completion handler called after ad load
  var completionHandler: GADMediationNativeLoadCompletionHandler?

  func loadNativeAd(
    for adConfiguration: GADMediationNativeAdConfiguration,
    completionHandler: @escaping GADMediationNativeLoadCompletionHandler
  ) {
    let adLoader = SampleNativeAdLoader()
    let sampleRequest = SampleNativeAdRequest()

    // The Google Mobile Ads SDK requires the image assets to be downloaded
    // automatically unless the publisher specifies otherwise by using the
    // GADNativeAdImageAdLoaderOptions object's disableImageLoading property. If
    // your network doesn't have an option like this and instead only ever
    // returns URLs for images (rather than the images themselves), your adapter
    // should download image assets on behalf of the publisher. This should be
    // done after receiving the native ad object from your network's SDK, and
    // before calling the connector's adapter:didReceiveMediatedNativeAd: method.
    sampleRequest.shouldDownloadImages = true
    sampleRequest.preferredImageOrientation = NativeAdImageOrientation.any
    sampleRequest.shouldRequestMultipleImages = false
    let options = adConfiguration.options
    for loaderOptions: GADAdLoaderOptions in options {
      if let imageOptions = loaderOptions as? GADNativeAdImageAdLoaderOptions {
        sampleRequest.shouldRequestMultipleImages =
          imageOptions.shouldRequestMultipleImages
        // If the GADNativeAdImageAdLoaderOptions' disableImageLoading property is
        // YES, the adapter should send just the URLs for the images.
        sampleRequest.shouldDownloadImages = !imageOptions.disableImageLoading
      } else if let mediaOptions = loaderOptions
        as? GADNativeAdMediaAdLoaderOptions
      {
        switch mediaOptions.mediaAspectRatio {
        case GADMediaAspectRatio.landscape:
          sampleRequest.preferredImageOrientation =
            NativeAdImageOrientation.landscape
        case GADMediaAspectRatio.portrait:
          sampleRequest.preferredImageOrientation =
            NativeAdImageOrientation.portrait
        default:
          sampleRequest.preferredImageOrientation = NativeAdImageOrientation.any
        }
      }
    }
    // This custom event uses the server parameter to carry an ad unit ID, which
    // is the most common use case.
    adLoader.delegate = self
    adLoader.adUnitID =
      adConfiguration.credentials.settings["parameter"] as? String
    self.completionHandler = completionHandler
    adLoader.fetchAd(sampleRequest)
  }
}

Objective-C

#import "SampleCustomEventNativeAd.h"

@interface SampleCustomEventNativeAd () <SampleNativeAdDelegate,
                                         GADMediationNativeAd> {
  /// The sample native ad.
  SampleNativeAd *_nativeAd;

  /// The completion handler to call when the ad loading succeeds or fails.
  GADMediationNativeLoadCompletionHandler _loadCompletionHandler;

  /// The ad event delegate to forward ad rendering events to the Google Mobile
  /// Ads SDK.
  id<GADMediationNativeAdEventDelegate> _adEventDelegate;
}
@end

- (void)loadNativeAdForAdConfiguration:
            (GADMediationNativeAdConfiguration *)adConfiguration
                     completionHandler:(GADMediationNativeLoadCompletionHandler)
                                           completionHandler {
  __block atomic_flag completionHandlerCalled = ATOMIC_FLAG_INIT;
  __block GADMediationNativeLoadCompletionHandler originalCompletionHandler =
      [completionHandler copy];

  _loadCompletionHandler = ^id<GADMediationNativeAdEventDelegate>(
      _Nullable id<GADMediationNativeAd> ad, NSError *_Nullable error) {
    // Only allow completion handler to be called once.
    if (atomic_flag_test_and_set(&completionHandlerCalled)) {
      return nil;
    }

    id<GADMediationNativeAdEventDelegate> delegate = nil;
    if (originalCompletionHandler) {
      // Call original handler and hold on to its return value.
      delegate = originalCompletionHandler(ad, error);
    }

    // Release reference to handler. Objects retained by the handler will also
    // be released.
    originalCompletionHandler = nil;

    return delegate;
  };

  SampleNativeAdLoader *adLoader = [[SampleNativeAdLoader alloc] init];
  SampleNativeAdRequest *sampleRequest = [[SampleNativeAdRequest alloc] init];

  // The Google Mobile Ads SDK requires the image assets to be downloaded
  // automatically unless the publisher specifies otherwise by using the
  // GADNativeAdImageAdLoaderOptions object's disableImageLoading property. If
  // your network doesn't have an option like this and instead only ever returns
  // URLs for images (rather than the images themselves), your adapter should
  // download image assets on behalf of the publisher. This should be done after
  // receiving the native ad object from your network's SDK, and before calling
  // the connector's adapter:didReceiveMediatedNativeAd: method.
  sampleRequest.shouldDownloadImages = YES;

  sampleRequest.preferredImageOrientation = NativeAdImageOrientationAny;
  sampleRequest.shouldRequestMultipleImages = NO;
  sampleRequest.testMode = adConfiguration.isTestRequest;

  for (GADAdLoaderOptions *loaderOptions in adConfiguration.options) {
    if ([loaderOptions isKindOfClass:[GADNativeAdImageAdLoaderOptions class]]) {
      GADNativeAdImageAdLoaderOptions *imageOptions =
          (GADNativeAdImageAdLoaderOptions *)loaderOptions;
      sampleRequest.shouldRequestMultipleImages =
          imageOptions.shouldRequestMultipleImages;

      // If the GADNativeAdImageAdLoaderOptions' disableImageLoading property is
      // YES, the adapter should send just the URLs for the images.
      sampleRequest.shouldDownloadImages = !imageOptions.disableImageLoading;
    } else if ([loaderOptions
                   isKindOfClass:[GADNativeAdMediaAdLoaderOptions class]]) {
      GADNativeAdMediaAdLoaderOptions *mediaOptions =
          (GADNativeAdMediaAdLoaderOptions *)loaderOptions;
      switch (mediaOptions.mediaAspectRatio) {
        case GADMediaAspectRatioLandscape:
          sampleRequest.preferredImageOrientation =
              NativeAdImageOrientationLandscape;
          break;
        case GADMediaAspectRatioPortrait:
          sampleRequest.preferredImageOrientation =
              NativeAdImageOrientationPortrait;
          break;
        default:
          sampleRequest.preferredImageOrientation = NativeAdImageOrientationAny;
          break;
      }
    } else if ([loaderOptions isKindOfClass:[GADNativeAdViewAdOptions class]]) {
      _nativeAdViewAdOptions = (GADNativeAdViewAdOptions *)loaderOptions;
    }
  }

  // This custom event uses the server parameter to carry an ad unit ID, which
  // is the most common use case.
  NSString *adUnit = adConfiguration.credentials.settings[@"parameter"];
  adLoader.adUnitID = adUnit;
  adLoader.delegate = self;

  [adLoader fetchAd:sampleRequest];
}

سواء تم جلب الإعلان بنجاح أو واجه خطأ، الاتصال بـ GADMediationNativeAdLoadCompletionHandler. في حالة النجاح، اجتياز الفئة التي تنفّذ GADMediationNativeAd بقيمة nil لمعامل الخطأ؛ في حالة الفشل، مرر بالخطأ الذي واجهناها.

عادةً، يتم تنفيذ هذه الطرق داخل استدعاءات من حزمة تطوير البرامج (SDK) التابعة لجهة خارجية التي ينفّذها المحوّل. في هذا المثال، نموذج حزمة SDK لدى SampleNativeAdDelegate مع استدعاءات ذات صلة:

Swift

func adLoader(
  _ adLoader: SampleNativeAdLoader, didReceive nativeAd: SampleNativeAd
) {
  extraAssets = [
    SampleCustomEventConstantsSwift.awesomenessKey: nativeAd.degreeOfAwesomeness
      ?? ""
  ]

  if let image = nativeAd.image {
    images = [GADNativeAdImage(image: image)]
  } else {
    let imageUrl = URL(fileURLWithPath: nativeAd.imageURL)
    images = [GADNativeAdImage(url: imageUrl, scale: nativeAd.imageScale)]
  }
  if let mappedIcon = nativeAd.icon {
    icon = GADNativeAdImage(image: mappedIcon)
  } else {
    let iconURL = URL(fileURLWithPath: nativeAd.iconURL)
    icon = GADNativeAdImage(url: iconURL, scale: nativeAd.iconScale)
  }

  adChoicesView = SampleAdInfoView()
  self.nativeAd = nativeAd
  if let handler = completionHandler {
    delegate = handler(self, nil)
  }
}

func adLoader(
  _ adLoader: SampleNativeAdLoader,
  didFailToLoadAdWith errorCode: SampleErrorCode
) {
  let error =
    SampleCustomEventUtilsSwift.SampleCustomEventErrorWithCodeAndDescription(
      code: SampleCustomEventErrorCodeSwift
        .SampleCustomEventErrorAdLoadFailureCallback,
      description:
        "Sample SDK returned an ad load failure callback with error code: \(errorCode)"
    )
  if let handler = completionHandler {
    delegate = handler(nil, error)
  }
}

Objective-C

- (void)adLoader:(SampleNativeAdLoader *)adLoader
    didReceiveNativeAd:(SampleNativeAd *)nativeAd {
  if (nativeAd.image) {
    _images = @[ [[GADNativeAdImage alloc] initWithImage:nativeAd.image] ];
  } else {
    NSURL *imageURL = [[NSURL alloc] initFileURLWithPath:nativeAd.imageURL];
    _images = @[ [[GADNativeAdImage alloc] initWithURL:imageURL
                                                 scale:nativeAd.imageScale] ];
  }

  if (nativeAd.icon) {
    _icon = [[GADNativeAdImage alloc] initWithImage:nativeAd.icon];
  } else {
    NSURL *iconURL = [[NSURL alloc] initFileURLWithPath:nativeAd.iconURL];
    _icon = [[GADNativeAdImage alloc] initWithURL:iconURL
                                            scale:nativeAd.iconScale];
  }

  // The sample SDK provides an AdChoices view (SampleAdInfoView). If your SDK
  // provides image and click through URLs for its AdChoices icon instead of an
  // actual UIView, the adapter is responsible for downloading the icon image
  // and creating the AdChoices icon view.
  _adChoicesView = [[SampleAdInfoView alloc] init];
  _nativeAd = nativeAd;

  _adEventDelegate = _loadCompletionHandler(self, nil);
}

- (void)adLoader:(SampleNativeAdLoader *)adLoader
    didFailToLoadAdWithErrorCode:(SampleErrorCode)errorCode {
  NSError *error = SampleCustomEventErrorWithCodeAndDescription(
      SampleCustomEventErrorAdLoadFailureCallback,
      [NSString stringWithFormat:@"Sample SDK returned an ad load failure "
                                 @"callback with error code: %@",
                                 errorCode]);
  _adEventDelegate = _loadCompletionHandler(nil, error);
}

ربط الإعلانات المدمجة مع المحتوى

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

لمعالجة هذه المشاكل، عند تلقّي حدث مخصّص عنصر إعلان مدمج مع المحتوى من حزمة SDK تعتمد على التوسط، يجب أن تستخدم فئة تنفذ GADMediationNativeAd، مثل SampleCustomEventNativeAd، إلى "خريطة" كائن الإعلان المدمج مع محتوى حزمة تطوير البرامج (SDK) التي تعتمد على التوسّط لكي يتطابق مع الواجهة المتوقعة في حزمة "SDK لإعلانات Google على الأجهزة الجوّالة".

سنُلقي الآن نظرة فاحصة على تفاصيل تنفيذ SampleCustomEventNativeAd

تخزين تعييناتك

من المتوقّع أن تطبّق ميزة "GADMediationNativeAd" سمات معيّنة ذات من مواقع حزمة SDK الأخرى:

Swift

var nativeAd: SampleNativeAd?

var headline: String? {
  return nativeAd?.headline
}

var images: [GADNativeAdImage]?

var body: String? {
  return nativeAd?.body
}

var icon: GADNativeAdImage?

var callToAction: String? {
  return nativeAd?.callToAction
}

var starRating: NSDecimalNumber? {
  return nativeAd?.starRating
}

var store: String? {
  return nativeAd?.store
}

var price: String? {
  return nativeAd?.price
}

var advertiser: String? {
  return nativeAd?.advertiser
}

var extraAssets: [String: Any]? {
  return [
    SampleCustomEventConstantsSwift.awesomenessKey:
      nativeAd?.degreeOfAwesomeness
      ?? ""
  ]
}

var adChoicesView: UIView?

var mediaView: UIView? {
  return nativeAd?.mediaView
}

Objective-C

/// Used to store the ad's images. In order to implement the
/// GADMediationNativeAd protocol, we use this class to return the images
/// property.
NSArray<GADNativeAdImage *> *_images;

/// Used to store the ad's icon. In order to implement the GADMediationNativeAd
/// protocol, we use this class to return the icon property.
GADNativeAdImage *_icon;

/// Used to store the ad's ad choices view. In order to implement the
/// GADMediationNativeAd protocol, we use this class to return the adChoicesView
/// property.
UIView *_adChoicesView;

- (nullable NSString *)headline {
  return _nativeAd.headline;
}

- (nullable NSArray<GADNativeAdImage *> *)images {
  return _images;
}

- (nullable NSString *)body {
  return _nativeAd.body;
}

- (nullable GADNativeAdImage *)icon {
  return _icon;
}

- (nullable NSString *)callToAction {
  return _nativeAd.callToAction;
}

- (nullable NSDecimalNumber *)starRating {
  return _nativeAd.starRating;
}

- (nullable NSString *)store {
  return _nativeAd.store;
}

- (nullable NSString *)price {
  return _nativeAd.price;
}

- (nullable NSString *)advertiser {
  return _nativeAd.advertiser;
}

- (nullable NSDictionary<NSString *, id> *)extraAssets {
  return
      @{SampleCustomEventExtraKeyAwesomeness : _nativeAd.degreeOfAwesomeness};
}

- (nullable UIView *)adChoicesView {
  return _adChoicesView;
}

- (nullable UIView *)mediaView {
  return _nativeAd.mediaView;
}

- (BOOL)hasVideoContent {
  return self.mediaView != nil;
}

قد توفر بعض الشبكات التي تعتمد على التوسط أصولاً إضافية غير تلك المحددة في SDK لإعلانات Google على الأجهزة الجوّالة. يتضمّن بروتوكول GADMediationNativeAd طريقة. يُسمى extraAssets الذي تستخدمه حزمة SDK لإعلانات Google على الأجهزة الجوّالة لاسترداد أي من هذه "الإضافية" الأصول من مصمم الخرائط.

مواد عرض الصور على الخريطة

إنّ ربط مواد عرض الصور أكثر تعقيدًا من ربط بيانات أبسط. أنواعًا مثل NSString أو double. قد يتم تنزيل الصور تلقائيًا أو يتم عرضها كقيم عناوين URL. ويمكن أن تتفاوت أيضًا كثافة وحدات البكسل بينها.

لمساعدتك في إدارة هذه التفاصيل، توفر حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" صف واحد (GADNativeAdImage). معلومات مواد عرض الصور (ما إذا كانت مادة عرض فعلية لـ UIImage الكائنات أو قيم NSURL فقط) إلى حزمة "SDK لإعلانات Google على الأجهزة الجوّالة". الذين يستخدمون هذه الفئة.

في ما يلي كيفية تعامل صف مصمم الخرائط مع عملية إنشاء GADNativeAdImage للاحتفاظ صورة الرمز:

Swift

if let image = nativeAd.image {
  images = [GADNativeAdImage(image: image)]
} else {
  let imageUrl = URL(fileURLWithPath: nativeAd.imageURL)
  images = [GADNativeAdImage(url: imageUrl, scale: nativeAd.imageScale)]
}

Objective-C

if (nativeAd.image) {
  _images = @[ [[GADNativeAdImage alloc] initWithImage:nativeAd.image] ];
} else {
  NSURL *imageURL = [[NSURL alloc] initFileURLWithPath:nativeAd.imageURL];
  _images = @[ [[GADNativeAdImage alloc] initWithURL:imageURL
                                               scale:nativeAd.imageScale] ];
}

أحداث الظهور والنقرات

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

تتبُّع النقرات ومرات الظهور باستخدام "SDK لإعلانات Google على الأجهزة الجوّالة"

إذا لم تكن حزمة تطوير البرامج التي تعتمد على التوسّط ميزة تتبُّع مرات الظهور والنقرات الخاصة بها، ولكن توفر طرقًا لتسجيل النقرات ومرات الظهور، ويمكن لحزمة SDK لإعلانات Google على الأجهزة الجوّالة وتتبع هذه الأحداث وإبلاغ المحوّل. بروتوكول GADMediationNativeAd تتضمن طريقتين: didRecordImpression: didRecordClickOnAssetWithName:view:viewController: التي يمكن للأحداث المخصّصة استخدامها يمكن تنفيذها لطلب الطريقة المقابلة في كائن "الإعلان المدمج مع المحتوى" الذي يعتمد على التوسّط:

Swift

func didRecordImpression() {
  nativeAd?.recordImpression()
}

func didRecordClickOnAsset(
  withName assetName: GADUnifiedNativeAssetIdentifier,
  view: UIView,
  wController: UIViewController
) {
  nativeAd?.handleClick(on: view)
}

Objective-C

- (void)didRecordImpression {
  if (self.nativeAd) {
    [self.nativeAd recordImpression];
  }
}

- (void)didRecordClickOnAssetWithName:(GADUnifiedNativeAssetIdentifier)assetName
                                 view:(UIView *)view
                       viewController:(UIViewController *)viewController {
  if (self.nativeAd) {
    [self.nativeAd handleClickOnView:view];
  }
}

لأنّ الفئة التي تنفّذ GADMediationNativeAd يشير إلى كائن الإعلان المدمج في نموذج حزمة تطوير البرامج (SDK)، ويمكنه استدعاء طريقة مناسبة على ذلك العنصر للإبلاغ عن نقرة أو مرة ظهور. لاحظ أن تستغرق طريقة didRecordClickOnAssetWithName:view:viewController: عملية واحدة المعلمة: العنصر View المقابل لمادة عرض الإعلان المدمج مع المحتوى التي تم استلامها النقرة.

تتبع النقرات ومرات الظهور باستخدام حزمة SDK التي تعتمد على التوسط

قد تفضّل بعض حِزم تطوير البرامج (SDK) التي تعتمد على التوسّط تتبُّع النقرات ومرات الظهور من تلقاء نفسها. ضِمن في هذه الحالة، يجب تنفيذ السمة handlesUserClicks handlesUserImpressions طريقة كما هو موضح في المقتطف أدناه. عن طريق العودة YES، أنت تشير إلى أنّ الحدث المخصّص يتحمل مسؤولية التتبُّع. هذه الأحداث، وسيتم إرسال إشعار إلى حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" عند وقوع هذه الأحداث.

يمكن أن تستخدم الأحداث المخصّصة التي تلغي تتبُّع النقرات ومرات الظهور didRenderInView: لتمرير طريقة عرض الإعلان المدمج مع المحتوى إلى حزمة تطوير البرامج (SDK) التي تعتمد على التوسّط كائن إعلان مدمج مع المحتوى للسماح لحزمة تطوير البرامج (SDK) التي تعتمد على التوسّط بإجراء التتبع الفعلي. العيّنة حزمة تطوير البرامج (SDK) من المشروع النموذجي للحدث المخصّص (الذي منه مقتطفات الرموز البرمجية لهذا الدليل) المتخذة) لا تستخدم هذا النهج" ولكن إذا حدث ذلك، سيتم تعديل رمز الحدث سيتم استدعاء طريقة setNativeAdView:view: كما هو موضح في المقتطف أدناه:

Swift

func handlesUserClicks() -> Bool {
  return true
}
func handlesUserImpressions() -> Bool {
  return true
}

func didRender(
  in view: UIView, clickableAssetViews: [GADNativeAssetIdentifier: UIView],
  nonclickableAssetViews: [GADNativeAssetIdentifier: UIView],
  viewController: UIViewController
) {
  // This method is called when the native ad view is rendered. Here you would pass the UIView
  // back to the mediated network's SDK.
  self.nativeAd?.setNativeAdView(view)
}

Objective-C

- (BOOL)handlesUserClicks {
  return YES;
}

- (BOOL)handlesUserImpressions {
  return YES;
}

- (void)didRenderInView:(UIView *)view
       clickableAssetViews:(NSDictionary<GADNativeAssetIdentifier, UIView *> *)
                               clickableAssetViews
    nonclickableAssetViews:(NSDictionary<GADNativeAssetIdentifier, UIView *> *)
                               nonclickableAssetViews
            viewController:(UIViewController *)viewController {
  // This method is called when the native ad view is rendered. Here you would
  // pass the UIView back to the mediated network's SDK. Playing video using
  // SampleNativeAd's playVideo method
  [_nativeAd setNativeAdView:view];
}

إعادة توجيه أحداث التوسّط إلى "SDK لإعلانات Google على الأجهزة الجوّالة"

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

من المهمّ أن يُعيد الحدث المخصّص توجيه أكبر عدد ممكن من طلبات معاودة الاتصال هذه. حتى يتلقّى تطبيقك هذه الأحداث المماثلة من نظام التشغيل SDK لإعلانات الأجهزة الجوّالة. إليك مثال على استخدام عمليات معاودة الاتصال:

وبذلك، تكون قد أكملت تنفيذ الأحداث المخصّصة للإعلانات المدمجة مع المحتوى. المثال الكامل متاح على GitHub.