الإشارات الآمنة هي بيانات مشفّرة يجمعها جهاز العميل ويشاركها مع مقدّمي عروض أسعار محدّدين. توضّح لك هذه الصفحة كيفية جمع الإشارات الآمنة وإرسالها إلى "مدير إعلانات Google" باستخدام حزمة تطوير البرامج للإعلانات التفاعلية (IMA SDK).
قبل البدء
قبل المتابعة، تأكَّد من أنّ لديك حزمة تطوير البرامج للإعلانات التفاعلية (IMA SDK) لنظام التشغيل iOS الإصدار 3.18.5 أو إصدار أحدث.
إنشاء واجهة محوِّل الإشارات الآمنة
لجمع الإشارات الآمنة وتقديمها، أنشئ فئات تنفّذ الواجهة:
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()
}
}
إعداد المحوّل
تُهيئ حزمة IMA SDK كل محوّل مرة واحدة من خلال استدعاء طريقة الإعداد الخاصة بالمحوّل. يجب تنفيذ هذه الطريقة لبدء أي تبعيات تشفير أو إعداد ذاكرات التخزين المؤقت أو إجراء حساب مسبق لأي إشارات تظل كما هي في جميع طلبات جمع الإشارات.
يعمل المثال التالي على إعداد المحوّل:
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 = ...;
}
}
}
جمع الإشارات
قبل بدء طلب عرض الإعلان، تستدعي حزمة IMA 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) أو التبعية الأذونات المطلوبة أو موافقة المستخدم للعمل.
تحديد إصدار المحوِّل
في سير العمل، تأكَّد من تحديد إصدار المحوِّل. تتضمّن حزمة تطوير البرامج للإعلانات التفاعلية (IMA 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. في كل طلب عرض إعلان، تتضمّن حزمة IMA 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 SDK إلا المحوّلات التي تسجّلها لدى Google.
التحقّق من صحة المحوّل
للتحقّق من صحة المحوِّل، أكمِل الأقسام التالية:
ضبط إعدادات تطبيق الاختبار
قبل التحقّق من صحة المحوِّل، اضبط تطبيق الاختبار. أكمِل الخطوات التالية:
أضِف حزمة تطوير البرامج للإعلانات التفاعلية (IMA SDK) إلى مشروع XCode.
أضِف محوّل الإشارات الآمنة إلى مشروع XCode.
التحقّق من الإشارات
للتحقّق من طول الإشارة الآمنة والقيمة المشفّرة وإصدار المحوّل وإصدار حزمة تطوير البرامج (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
}
}