Se actualizó este documento.
La traducción en español no está disponible todavía.
Actualización del documento en inglés: 5 ago. 2021
Actualización del documento en español: 26 nov. 2018

Server-to-Server: iOS Client Setup Guide

In-house mediation is not publicly available

In-house bidding with Audience Network is currently in Closed Beta and is not publicly available. We'll provide further updates if this changes.

As an alternative, you can access Audience Network Bidding through one of the mediation platforms we partner with.

This guide describes how you can build an iOS Client App. In the step-by-step guide below, we will be using the example of sending an Auction Request to your Auction Server on an interstitial ad. Make sure that you are already familiar with using Audience Network interstitial ads. Bidding also supports Native, Banner, Interstitial, In-stream Video and Rewarded Video formats. When you are using ad formats other than interstitial format, you can change your Server Settings.

Prerequisites

iOS Client Side Setup Steps

Step 1: Making an auction request from iOS client

Step 2: Loading the ad from bid response on iOS client

iOS Client Side Setup Steps

Step 1: Making an auction request from iOS client

On the client side, we need to gather the required parameters for the auction request, and send it to the auction server using HTTP request. Here is an example implementation in iOS for making the auction request specified by the format above:

- (NSMutableURLRequest *)getRequest {

NSURL *url = [NSURL URLWithString:@"${AUCTION_SERVER_ENDPOINT}"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSDictionary *buyerToken = @{@"audience_network": [FBAdSettings bidderToken]};
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString *bundleVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString *idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
int32_t dnt = [[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled] ? 0 : 1;
NSDictionary *bodyDict = @{@"app_id": @"101",
@"placement_id": @"1",
@"bundle": bundleIdentifier,
@"bundle_version": bundleVersion,
@"ifa": idfa,
@"coppa": @0,
@"dnt": [NSNumber numberWithInt:dnt],
@"buyer_tokens": buyerToken,
@"test": @1};
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:bodyDict options:0 error:nil];
[request setHTTPBody:bodyData];
[request setHTTPMethod:@"POST"];
return request;
}

Here is the sample code snippet of a static function that sends the auction request to the server, and invoke the callback methods with the server response:

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithRequest: self.getRequest
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
if (!error) {
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if (json) {
self.placementId = json[@"placement_id"];
self.adFormat = json[@"ad_format"];
self.platformName = json[@"platform_name"];
self.platformPlacementId = json[@"platform_placement_id"];
self.payload = json[@"bid_payload"];
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Ad is available";
});
} else {
NSLog(@"Requesting Error: unknow error.");
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Ad is NOT available";
});
}
} else {
NSLog(@"Requesting Error: %@", error.localizedDescription);
self.placementId = nil;
self.adFormat = nil;
self.platformName = nil;
self.platformPlacementId = nil;
self.payload = nil;
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Ad is NOT available";
});
}
}] resume];

Step 2: Loading the ad from bid response on iOS client

On the client app, using the response parameters, we can tell which platform won the auction, and load the ad. If the auction was successful and Audience Network won the auction, the response parameters will contain a payload string which we can load the ad from. We can call the loadAdWithBidPayload method on the correct ad format class to load the ad. Here are the implemented auction request callback methods:

- (IBAction)didShow:(UIButton *)sender {

if ([self.statusLabel.text isEqualToString:@"Ad is NOT available"]) {
return;
}
if (![self.platformName isEqualToString:@"audience_network"] ||
![self.adFormat isEqualToString:@"interstitial"] ||
!self.platformPlacementId) {
self.statusLabel.text = @"Ad is NOT available";
return;
}
self.interstitialAd = [[FBInterstitialAd alloc] initWithPlacementID:self.platformPlacementId];
self.interstitialAd.delegate = self;
[self.interstitialAd loadAdWithBidPayload:self.payload];
}

As a result, the sample app will load the ad if Audience Network won the bid, or display the error message received from the auction server.

Next: Client Step-by-Step Integration