إنشاء محوِّل إشارات آمنة

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

قبل البدء

قبل المتابعة، تأكَّد من أنّ لديك الإصدار 3.18.5 أو إصدارًا أحدث من حزمة تطوير البرامج (SDK) لإعلانات الوسائط التفاعلية على نظام التشغيل iOS.

إنشاء واجهة محوّل الإشارة الآمنة

لجمع الإشارات الآمنة وتقديمها، أنشئ فئات تنفّذ الواجهة التالية:

Objective-C

  • MySecureSignalsAdapter.h:
#import <Foundation/Foundation.h>
#import <GoogleInteractiveMediaAds/GoogleInteractiveMediaAds.h>
/** An example implementation of Secure Signals adapter. */
@interface MySecureSignalsAdapter : NSObject <IMASecureSignalsAdapter>
@end
  • MySecureSignalsAdapter.m:
@implementation MySecureSignalsAdapter

  /**
* Default constructor with no arguments for IMA SDK to instantiate this class.
*/
- (instancetype)init {
  self = [super init];

  return self;
}
@end

Swift

import Foundation
import GoogleInteractiveMediaAds

/** An example implementation of Secure Signals adapter. */
@objc(MySecureSignalsAdapter)
public class MySecureSignalsAdapter: IMASecureSignalsAdapter {
  /**
  * Default constructor with no arguments for IMA SDK to instantiate this class.
  */
  override init() {
    super.init()
  }
}

إعداد المحوّل

تُعدّ حزمة تطوير البرامج لإعلانات الوسائط التفاعلية كل محوّل مرة واحدة من خلال استدعاء طريقة الإعداد الخاصة بالمحوّل. نفِّذ هذه الطريقة لبدء أي تبعيات تشفير أو إعداد ذاكرات تخزين مؤقت أو إجراء أي عمليات حسابية مسبقة لأي إشارات تظل كما هي في جميع طلبات جمع الإشارات.

يوضّح المثال التالي كيفية تهيئة المحوّل:

Objective-C

...
@interface MySecureSignalsAdapter
@property(nonatomic) NSError *initError;
@end
...
/**
* Initialize your SDK and any dependencies.
* IMA SDK calls this function exactly once before signal collection.
*/
- (instancetype)init {
  self = [super init];
  @try {
    // Initialize your SDK and any dependencies.
    ...
  }
  @catch(NSException *exception) {
    // Build NSError to be passed by Signal Collector.
    _initError = ...;
  }
  return self;
}
...

Swift

...
@objc(MySecureSignalsAdapter)
public class MySecureSignalsAdapter: IMASecureSignalsAdapter {
...
  private var initError

  override init() {
    super.init()

    do {
      // Initialize your SDK and any dependencies.
      ...
    } catch {
      // Build NSError to be passed by Signal Collector.
      self.initError = ...;
    }
  }
}

جمع الإشارات

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

تجمع الأمثلة التالية الإشارات الآمنة من خلال دالة رد الاتصال:

Objective-C

...
/**
* Invokes your SDK to collect, encrypt and pass the signal collection results to IMA SDK.
* IMA SDK calls this function before each ad request.
*
* @param completion A callback function to pass signal collection results to IMA SDK.
*/
- (void)collectSignalsWithCompletion:(IMASignalCompletionHandler)completion {
  // Output any initialization errors
  if (self.initError) {
    completion(nil, self.initError);
    return;
  }
  @try {
    // Collect and encrypt the signals.
    NSString *signals = ...
    // Pass the encrypted signals to IMA SDK.
    completion(signals, nil);
  }
  @catch(NSException *exception) {
    NSError *collectSignalError = ...;
    // Pass signal collection failures to IMA SDK.
    completion(nil, collectSignalError);
  }
}
...

Swift

...
  /**
  * Invokes your SDK to collect, encrypt and pass the signal collection results to IMA SDK.
  * IMA SDK calls this function before each ad request.
  *
  * @param completion A callback function to pass signal collection results to IMA SDK.
  */
  public func collectSignals(completion: @escaping IMASignalCompletionHandler) {
    if (self.initError) {
      completion(nil, self.initError)
      return
    }

    do {
      // Collect and encrypt the signals.
      var signals = ...
      // Pass the encrypted signals to IMA SDK.
      completion(signals, nil)
    } catch {
      NSError collectSignalError = ...
      // Pass signal collection failures to IMA SDK.
      completion(nil, collectSignalError)
    }
  }
...

الإبلاغ عن أخطاء

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

في ما يلي الأخطاء التي قد تظهر:

  • لم يتم العثور على حزمة تطوير البرامج (SDK) أو إحدى التبعيات في التطبيق.
  • لا تتضمّن حزمة SDK أو إحدى التبعيات الإذن أو موافقة المستخدم المطلوبَين للعمل.

تحديد إصدار المحوّل

في سير العمل، تأكَّد من تحديد إصدار المحوّل. تتضمّن حزمة تطوير البرامج لإعلانات الوسائط التفاعلية إصدار المحوّل في كل طلب إعلان، وتمرِّرها مع الإشارات الآمنة في طلب عرض سعر.

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

يوضّح المثال التالي إصدار المحوّل:

Objective-C

...
/**
* Specifies this adapter's version.
*/
static NSInteger const VersionMajor = 1;
static NSInteger const VersionMinor = 0;
static NSInteger const VersionPatch = 1;
...
/**
* @return The version of this adapter.
*         IMA SDK calls this function before each ad request.
*/
+ (IMAVersion *)adapterVersion {
  // The version of the SecureSignals Adapter.
  IMAVersion *adapterVersion = [[IMAVersion alloc] init];
  adapterVersion.majorVersion = VersionMajor;
  adapterVersion.minorVersion = VersionMinor;
  adapterVersion.patchVersion = VersionPatch;
  return adapterVersion;
}
...

Swift

...
  /**
  * Specifies this adapter's version.
  */
  static let VersionMajor = 1;
  static let VersionMinor = 0;
  static let VersionPatch = 1;
...
  /**
  * @return The version of this adapter.
  *         IMA SDK calls this function before each ad request.
  */
  public static func adapterVersion() -> IMAVersion {
    let adapterVersion = IMAVersion()
    adapterVersion.majorVersion = self.VersionMajor
    adapterVersion.minorVersion = self.VersionMinor
    adapterVersion.patchVersion = self.VersionPatch
    return adapterVersion
  }
...

إرجاع إصدار وقت تشغيل حزمة SDK

يمكنك تصميم محوّل للعمل مع إصدارات متعددة من حزمة تطوير البرامج (SDK). لكي يعمل المحوّل مع إصدارات متعدّدة، تأكَّد من عرض إصدار وقت التشغيل من حزمة SDK. في كل طلب إعلان، تتضمّن حزمة تطوير البرامج للإعلانات التفاعلية إصدار وقت التشغيل مع إصدار أداة الربط.

تطلب الأمثلة التالية إصدار وقت تشغيل حزمة SDK وتعرضه:

Objective-C

...
/**
* @return The version of your SDK that this adapter is depending on.
*         IMA SDK calls this function before each ad request.
*/
+ (IMAVersion *)adSDKVersion {
  // Request the version from your SDK and convert to an IMAVersion.
  int mySDKVersion[3] = ...

  IMAVersion *adSDKVersion = [[IMAVersion alloc] init];
  adSDKVersion.majorVersion = mySDKVersion[0];
  adSDKVersion.minorVersion = mySDKVersion[1];
  adSDKVersion.patchVersion = mySDKVersion[2];

  return adSDKVersion;
}
...

Swift

...
  /**
  * @return The version of your SDK that this adapter is depending on.
  *         IMA SDK calls this function before each ad request.
  */
public static func adSDKVersion() -> IMAVersion {
    // Request the version from your SDK and convert to an IMAVersion.
    let mySDKVersion = ...

    let adSDKVersion = IMAVersion()
    adSDKVersion.majorVersion = mySDKVersion[0]
    adSDKVersion.minorVersion = mySDKVersion[1]
    adSDKVersion.patchVersion = mySDKVersion[2]
    return adSDKVersion
  }
...

تسجيل المحوّل لدى Google

لكي تسمح Google للمحوّل بجمع الإشارات، عليك تسجيل اسم فئة iOS لدى Google. لا تبدأ حزمة تطوير البرامج لإعلانات الوسائط التفاعلية (IMA) في إعداد سوى برامج التكيّف التي تسجّلها لدى Google.

التحقّق من صحة المحوّل

للتحقّق من صحة المحوّل، أكمِل الأقسام التالية:

ضبط تطبيق الاختبار

قبل التحقّق من صحة المحوّل، عليك إعداد تطبيق الاختبار. أكمِل الخطوات التالية:

  1. أضِف حزمة تطوير البرامج لإعلانات الوسائط التفاعلية إلى ملف pod:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '10'
    target "BasicExample" do
      pod 'GoogleAds-IMA-iOS-SDK', '~> 3.17.0'
    end
    
  2. ثبِّت حزمة تطوير البرامج لإعلانات الوسائط التفاعلية (IMA) باستخدام CocoaPods. للحصول على تعليمات حول تثبيت حزمة تطوير البرامج لإعلانات الوسائط التفاعلية (IMA) من خلال CocoaPods، يُرجى الاطّلاع على البدء.

  3. في مشروع XCode، أضِف المحوّل وحزمة SDK وأي تبعيات أخرى أضفتها.

التحقّق من الإشارات

للتحقّق من طول الإشارة الآمنة والقيمة المشفّرة وإصدار المحوّل وإصدار حزمة تطوير البرامج (SDK)، تواصَل مع فريق الدعم لمشاركة سجلّ حركة البيانات التي تمّت مراقبتها.

مراجعة الأمثلة الكاملة

يتضمّن هذا القسم المثال المكتمل لجميع الخطوات ويمكنك الرجوع إليه.

Objective-C

  • MySecureSignalsAdapter.h:
#import <Foundation/Foundation.h>
#import <GoogleInteractiveMediaAds/GoogleInteractiveMediaAds.h>

/** An example implementation of Secure Signals adapter. */
@interface MySecureSignalsAdapter : NSObject <IMASecureSignalsAdapter>
@end
  • MySecureSignalsAdapter.m:
#import "path/to/MyExampleSecureSignalsAdapter.h"

@interface MySecureSignalsAdapter
@property(nonatomic) NSError *initError;
@end

static NSInteger const VersionMajor = 1;
static NSInteger const VersionMinor = 0;
static NSInteger const VersionPatch = 1;

@implementation MySecureSignalsAdapter
/**
* Initialize your SDK and any dependencies.
* IMA SDK calls this function exactly once before signal collection.
*/
- (instancetype)init {
  self = [super init];
  @try {
    // Initialize your SDK and any dependencies.
    ...
  }
  @catch(NSException *exception) {
    // Build NSError to be passed by Signal Collector.
    _initError = ...;
  }
  return self;
}
/**
* Invokes your SDK to collect, encrypt and pass the signal collection results to IMA SDK.
* IMA SDK calls this function before each ad request.
*
* @param completion A callback function to pass signal collection results to IMA SDK.
*/
- (void)collectSignalsWithCompletion:(IMASignalCompletionHandler)completion {
  if (self.initError) {
    completion(nil, self.initError);
    return;
  }
  @try {
    // Collect and encrypt the signals.
    NSString *signals = ...
    // Pass the encrypted signals to IMA SDK.
    completion(signals, nil);
  }
  @catch(NSException *exception) {
    NSError *collectSignalError = ...;
    // Pass signal collection failures to IMA SDK.
    completion(nil, collectSignalError);
  }
}
/**
* @return The version of this adapter.
*         IMA SDK calls this function before each ad request.
*/
+ (IMAVersion *)adapterVersion {
  // The version of the SecureSignals Adapter.
  IMAVersion *adapterVersion = [[IMAVersion alloc] init];
  adapterVersion.majorVersion = VersionMajor;
  adapterVersion.minorVersion = VersionMinor;
  adapterVersion.patchVersion = VersionPatch;
  return adapterVersion;
}

/**
  * @return The version of your SDK that this adapter depends on.
  *         IMA SDK calls this function before each ad request.
  */
+ (IMAVersion *)adSDKVersion {
  // Request the version from your SDK and convert to an IMAVersion.
  int mySDKVersion[3] = ...

  IMAVersion *adSDKVersion = [[IMAVersion alloc] init];
  adSDKVersion.majorVersion = mySDKVersion[0];
  adSDKVersion.minorVersion = mySDKVersion[1];
  adSDKVersion.patchVersion = mySDKVersion[2];

  return adSDKVersion;
}

@end

Swift

@objc(MySecureSignalsAdapter)
public class MySecureSignalsAdapter: IMASecureSignalsAdapter {
  static let VersionMajor = 1;
  static let VersionMinor = 0;
  static let VersionPatch = 1;

  private var initError

  override init() {
    super.init()

    do {
      // Initialize your SDK and any dependencies.
      ...
    } catch {
      // Build NSError to be passed by Signal Collector.
      self.initError = ...;
    }
  }

  public func collectSignals(completion: @escaping IMASignalCompletionHandler) {
    if (self.initError) {
      completion(nil, self.initError)
      return
    }

    do {
      // Collect and encrypt the signals.
      var signals = ...
      // Pass the encrypted signals to IMA SDK.
      completion(signals, nil)
    } catch {
      NSError collectSignalError = ...
      // Pass signal collection failures to IMA SDK.
      completion(nil, collectSignalError)
    }      
  }

  public static func adapterVersion() -> IMAVersion {
    let adapterVersion = IMAVersion()
    adapterVersion.majorVersion = self.VersionMajor
    adapterVersion.minorVersion = self.VersionMinor
    adapterVersion.patchVersion = self.VersionPatch
    return adapterVersion
  }

  public static func adSDKVersion() -> IMAVersion {
    // Request the version from your SDK and convert to an IMAVersion.
    let mySDKVersion = ...

    let adSDKVersion = IMAVersion()
    adSDKVersion.majorVersion = mySDKVersion[0]
    adSDKVersion.minorVersion = mySDKVersion[1]
    adSDKVersion.patchVersion = mySDKVersion[2]
    return adSDKVersion
  }
}