Tín hiệu an toàn là dữ liệu được mã hoá, được thu thập trên thiết bị của khách hàng và chia sẻ với một số bên đặt giá thầu. Hướng dẫn này cho bạn biết cách thu thập và gửi tín hiệu an toàn đến Google Ad Manager bằng SDK IMA.
API tín hiệu an toàn yêu cầu phiên bản 3.18.1 trở lên của SDK IMA cho iOS.
Để chọn tín hiệu và bên đặt giá thầu, đồng thời bật tính năng chia sẻ tín hiệu an toàn, hãy xem phần Chia sẻ tín hiệu an toàn với bên đặt giá thầu.
Sử dụng nhà cung cấp tín hiệu bên thứ ba
Để sử dụng tín hiệu an toàn, bạn phải triển khai một lớp bộ chuyển đổi bộ thu tín hiệu trong ứng dụng của mình để thu thập tín hiệu, mã hoá tín hiệu và truyền tín hiệu đó đến SDK IMA.
Làm theo hướng dẫn của nhà cung cấp bên thứ ba để thiết lập tài khoản với họ, bao gồm cả các khung và thiết lập bộ chuyển đổi tín hiệu an toàn của họ trong ứng dụng của bạn.
IMA SDK cho iOS sẽ tự động khởi chạy từng bộ chuyển đổi tín hiệu an toàn mà không cần thay đổi nào khác đối với mã của bạn.
Sau đây là ví dụ về cách bạn có thể thêm một bộ chuyển đổi tín hiệu an toàn vào dự án của mình:
Gửi dữ liệu tuỳ chỉnh
Ngoài việc sử dụng nhà cung cấp tín hiệu bên thứ ba, bạn cũng có thể thu thập, mã hoá và gửi tín hiệu bằng dữ liệu tuỳ chỉnh. Trước khi có thể gửi tín hiệu an toàn bằng dữ liệu tuỳ chỉnh, bạn phải bật tín hiệu tuỳ chỉnh trong Ad Manager.
Đối với mỗi yêu cầu phát trực tiếp, hãy làm như sau:
- Tạo một đối tượng
IMASecureSignals
chứa dữ liệu tuỳ chỉnh đã mã hoá dưới dạng một chuỗi. - Thêm đối tượng
IMASecureSignals
vào yêu cầu truyền phát trực tiếp bằng cách đặt thuộc tínhIMAStreamRequest.secureSignals
:
Objective-C
app/ViewController.m
- (void)requestStream {
// Create a stream request. Use one of "Livestream request" or "VOD request",
// depending on your type of stream.
IMAStreamRequest *request;
if (kStreamType == StreamTypeLive) {
// Livestream request. Replace the asset key with your value.
request = [[IMALiveStreamRequest alloc] initWithAssetKey:kLiveStreamAssetKey
networkCode:kNetworkCode
adDisplayContainer:self.adDisplayContainer
videoDisplay:self.imaVideoDisplay
userContext:nil];
} else {
// VOD request. Replace the content source ID and video ID with your values.
request = [[IMAVODStreamRequest alloc] initWithContentSourceID:kVODContentSourceID
videoID:kVODVideoID
networkCode:kNetworkCode
adDisplayContainer:self.adDisplayContainer
videoDisplay:self.imaVideoDisplay
userContext:nil];
}
IMASecureSignals *signals =
[[IMASecureSignals alloc] initWithCustomData:@"My encoded signal string"];
request.secureSignals = signals;
[self.adsLoader requestStreamWithRequest:request];
}
Swift
app/ViewController.swift
func requestStream() {
// Create a stream request. Use one of "Livestream request" or "VOD request".
let signals = IMASecureSignals(customData: "My encoded signal string")
if ViewController.requestType == StreamType.live {
// Livestream request.
let request = IMALiveStreamRequest(
assetKey: ViewController.assetKey,
networkCode: ViewController.networkCode,
adDisplayContainer: adDisplayContainer!,
videoDisplay: imaVideoDisplay,
userContext: nil)
request.secureSignals = signals
adsLoader?.requestStream(with: request)
} else {
// VOD stream request.
let request = IMAVODStreamRequest(
contentSourceID: ViewController.contentSourceID,
videoID: ViewController.videoID,
networkCode: ViewController.networkCode,
adDisplayContainer: adDisplayContainer!,
videoDisplay: imaVideoDisplay,
userContext: nil)
request.secureSignals = signals
adsLoader?.requestStream(with: request)
}
}