Amazon_iOS_Banner - imobile/app-mediation GitHub Wiki

※以下の文書はAmazon Publisher ServicesのドキュメントをAmazonの許諾を得て転載したものです。

Banner Ads for iOS

Before you start, please note that DTBAdLoader holds a weak reference to DTBAdCallback. If you are requesting for an ad in a separate class, make sure that your view controller holds a strong reference to that class instance. Failure to do so will result in an error.

An example is shown in our sample app within the SDK package. You will need to declare MyAdHandler class variable in the ViewController interface like so:

#import "ViewController.h"
@interface ViewController() {
   // Your class that contains the APS ad request code
   MyAdHandler *myAdHandler;
}
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    myAdHandler = [[MyAdHandler alloc] init];
    [myAdHandler loadWithUIViewController:self width:320 height:50 slotUUID:@"Your_Slot_Id"];
    //Please see our sample app for more details.
}

Add Banner Ads

  • In ViewController.h file, import DTBiOSSDK by adding #import <DTBiOSSDK/DTBiOSSDK.h>
  • Implement DTBAdCallback protocol into your class and set up the onSuccess and the onFailure methods. Once APS returns a response, either the onSuccess or the onFailure method will execute. Your ViewController.h file should look like the following:
#import <UIKit/UIKit.h>
#import <DTBiOSSDK/DTBiOSSDK.h>

@interface ViewController : UIViewController<DTBAdCallback>
@end
  • In the ViewController.m file, make a request to APS. To do so, create an instance of DTBAdSize and insert the ad size and the slotUUID.
  • Instantiate DTBAdLoader and set the size to the DTBAdSize object that you defined.
  • Call loadAd() to request APS for a bid.
  • Only a single ad size and slotUUID is supported per bid request.
#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    DTBAdSize *size = [[DTBAdSize alloc] initBannerAdSizeWithWidth:320 height:50 andSlotUUID:@"YOUR_SLOT_UUID"];
    DTBAdLoader *adLoader = [DTBAdLoader new];
    [adLoader setSizes:size, nil];
    [adLoader loadAd:self];
}

#pragma mark - DTBAdCallback
- (void)onFailure: (DTBAdError)error {
    NSLog(@"Failed to load ad :(");
    /**Please implement the logic to send ad request without our parameters if you want to
     show ads from other ad networks when Amazon ad request fails**/
}

- (void)onSuccess: (DTBAdResponse *)adResponse {
    /**Build the ad request to your ad server. This portion will differ depending on your 
     ad server**/
}
@end