Ti ringraziamo per la visita. Questa pagina è per il momento disponibile solo in inglese.

Quick Start Guide for iOS

The Quick Start Guide provides you step-by-step instructions for incorporating Amazon Mobile Ads into your app. The Amazon Mobile Ads API currently supports static image banners, expandable rich media banners with videos, and interstitials.

Before You Use the Amazon Mobile Ads API

The Amazon Mobile Ads API for iOS requires iOS 8.0 or later and assumes you have XCode 7.1 installed or later, and are familiar with iOS development.

Amazon Mobile Ads API and iOS 9 App Transport Security

Apple introduced additional Cocoa keys that developers are required to use in all apps which access the media library (contacts, calendars, photos, or location) on iOS10 or later. This change ensures that users have to grant permission for an app to access the media library.

The iOS SDK requires permissions to the user’s calendar for certain MRAID 2.0 functionalities. Access to the calendar may be required by some ads that want to schedule events on the user’s calendar. An example would be an ad for an upcoming event or movie that would need to use the calendar. An app that integrates the Amazon Mobile Ads iOS SDK must include theNSCalendarsUsageDescription key in the Info.plist file to access the user’s Calendar data. If this purpose string key is not included, the app exits when it tries to access the data.

We recommend that the following description be used in the application.

%%APP%% would like to schedule events on your calendar.

Where %%APP%% is the app developer's name.

Account Registration - Self Service

Sign in to your Amazon Apps & Games Developer Portal account, which you can access through the Amazon Developer Services Page. If you do not already have one, you will be prompted to create an account.

Submit Your Payment Information and Tax Information

Submit your payment information through the Payment Information Page and your tax information through the Tax Identity Interview Page (skip this step if you have already submitted this information through the Amazon Apps & Games Developer Portal). This information is required to receive ads.

Please note that if you are performing services using the Amazon Mobile Ad Network outside of the US, you still need to complete the Service Tax Identity Interview to enable us to report your tax obligations accurately.

The Service Tax Identity Interview, is a self-service interview process designed to guide you through entering your required taxpayer information. You can find more information about the tax identity interview in the Service Tax Identity Interview Guide. For additional information see Set up Tax Forms.

Obtain an Application Key

Once signed in, click on the My Apps tab and select an existing app or click the Mobile Ads tab and click the Register New IOS App button. When you create a new app, fill in the App title, answer the child-directed question and click Create Identifier. It's important to note that apps that are directed at children under 13 are not eligible to participate in the Amazon Mobile Ad Network. See Personal Information and COPPA in the FAQ to learn more.

If you answer that your app is not directed at children under 13, the next screen will show the unique Application Key value, which is a 32-character globally unique alphanumeric string that is used to identify your app. The same Application Key can be used across platforms, but each distinct app must have a unique Application Key. For example, the IMDb app uses the same Application Key on Android phone and Fire tablets, but the IMDb Trivia app has a different Application Key.

The Application Key is used in the setAppKey call mentioned in step 2 below, and your developer reports will aggregate data by Application Key. Proper use of your Application Key permits accurate tracking, reporting, and accrual of advertising fees.

Note: If you use an Application Key that is issued for one app in connection with the display of ads on a second app, we will not pay you for any resulting impression, click or other user action relating to ads on the second app.

Enabling Ads in iOS Apps

This section of the Quick Start Guide steps you through adding ads to an existing iOS app Xcode project:

1. Incorporate the API into Your Project

Add the AmazonAd iOS framework to your project

In XCode:

  1. Open your app in XCode
  2. Click on your project file and Go to Build Phases -> Link Binary With Libraries.
  3. Add the AmazonAd framework located at AmazonAd.framework
  4. Add the following frameworks if they are not already linked
    • Add the AdSupport.framework
    • Add the CoreLocation.framework
    • Add the SystemConfiguration.framework
    • Add the CoreTelephony.framework
    • Add the MediaPlayer.framework
    • Add the EventKit.framework
    • Add the EventKitUI.framework
    • Add the StoreKit.framework
    • Add the QuartzCore.framework
    • Add the JavaScriptCore.framework
    • Add the SafariServices.framework

2. Set Your Application Key

You must set your Application Key in order to receive ads. This allows Amazon to track your impressions and clicks, and associate them with your account. You should have your app call the ` AmazonAdRegistration setAppKey() ` method on every app start using the Application Key from the Amazon Mobile App Distribution. You could add this call to your AppDelegate's didFinishLaunchingWithOptions method.

Here's an example of setAppKey in didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.
  [[AmazonAdRegistration sharedRegistration] setAppKey:@"0123456789ABCDEF0123456789ABCDEF"]];
}

3. Add the Amazon Ad to Your App

The Amazon Mobile Ads API supports both banner ads and interstitial ads. Banner ads, which include static click-through ads as well as rich media expandable ads, are created using AmazonAdView. Meanwhile, interstitial ads are full-screen ads that are created via AmazonInterstitialAd objects.

Adding Banner Ads through Objective-C Code

To retrieve and display a banner ad, you will use an instance of AmazonAdView. To load an ad, call the AmazonAdView loadAd method, which uses a background thread to request an ad from the Amazon Mobile Ad Network. Only one ad can be loading or displayed by a given AmazonAdView at a given time. To check if a particular ad is loading, you can call the method AmazonAdView isLoading . When requesting an ad, you can also set a number of optional targeting parameters; these are covered on the Ad Targeting Options Page. Below is an example of a simplified loadAd call placed in one of the ViewController's viewDidLoad method:

(void)viewDidLoad {

  [super viewDidLoad];

  // Load an ad
  // Create an AmazonAdView instance with size 320x50.
  self.amazonAdView = [AmazonAdView amazonAdViewWithAdSize:AmazonAdSize_320x50];

  // Set the adOptions.
  AmazonAdOptions *options = [AmazonAdOptions options];

  // Turn on isTestRequest to load a test ad

  options.isTestRequest = YES;

  // Register the ViewController with the delegate to receive callbacks.
  amazonAdView.delegate = self;

  // Call loadAd
  [amazonAdView loadAd:options];

  // Ad the AmazonAdView to your viewController’s view.
  [self.view addSubView:amazonAdView];

Note: The above implementation uses manual size ads. To have the Amazon Mobile Ads iOS SDK automatically select the ad's size based on the ad view's size and the device's screen size, make sure to follow the guidelines in the Auto Ad Size section.

Here's how you would implement the AmazonAdViewDelegate protocol within your ViewController. The viewControllerForPresentingModelView protocol method should be implemented so that the AmazonAdView is aware of the ViewController that will be used for presenting/dismissing modal views, such as the browser view when a user clicks on an Ad. You may also choose to lazily add the AmazonAdView to your parent view in the adViewDidLoad optional callback method:

#pragma mark AmazonAdViewDelegate
// @required
- (UIViewController *)viewControllerForPresentingModalView {
 return self;
}

// @optional
- (void)adViewWillExpand:(AmazonAdView *)view {
 NSLog(@"Will present modal view for an ad. Its time to pause other activities.");
}

// @optional
- (void)adViewDidCollapse:(AmazonAdView *)view {
 NSLog(@"Modal view has been dismissed, its time to resume the paused activities.");
}

// @optional
- (void)adViewDidLoad:(AmazonAdView *)view {
 NSLog(@"Successfully loaded an ad");
}

// @optional
- (void)adViewDidFailToLoad:(AmazonAdView *)view withError:(AmazonAdError *)error {
  NSLog(@"Ad Failed to load. Error code %d: %@", error.errorCode, error.errorDescription);
}

Adding Interstitial Ads through Objective-C Code

To retrieve and display an interstitial ad, you will use an instance of AmazonAdInterstitial. To load an interstitial, call the AmazonAdInterstitial load method, which uses a background thread to request an interstitial from the Amazon Mobile Ad Network. Only one interstitial can be loading for a given AmazonAdInterstitial at a given time. When loading an interstitial, you can also set a number of optional targeting parameters; these are covered on the Ad Targeting Options Page. Once loaded, interstitialDidLoad callback is fired and the interstitial is ready for showing. AmazonAdInterstitial also provides the isReady property to check the readiness of the interstitial for convenience. To show the interstitial from a specified view controller, call AmazonAdInterstitial presentFromViewController which will further trigger interstitialWillPresent: and interstitialDidPresent: callbacks. Only one interstitial can be shown full screen for all instances of AmazonAdInterstitial at any time. Upon the user dismissing the interstitial, interstitialWillDismiss: and interstitialDidDismiss: callbacks will be triggered. Below is an code excerpt from InterstitialAdsUniversalSample on loading and showing an interstitial with callback implementations:

(void)viewDidLoad
{
    [super viewDidLoad];

    // Create an interstitial
    self.interstitial = [AmazonAdInterstitial amazonAdInterstitial];

    // Register the ViewController with the delegate to receive callbacks.
    self.interstitial.delegate = self;
}

- (IBAction)loadAmazonInterstitial:(UIButton *)sender
{
    self.loadStatusLabel.text = @"Loading interstitial...";

    // Set the adOptions.
    AmazonAdOptions *options = [AmazonAdOptions options];

   // Turn on isTestRequest to load a test interstitial
    options.isTestRequest = YES;

    // Load an interstitial
    [self.interstitial load:options];
}

- (IBAction)showAmazonInterstitial:(UIButton *)sender
{
    // Present the interstitial on screen
    [self.interstitial presentFromViewController:self];
}

#pragma mark - AmazonAdInterstitialDelegate
- (void)interstitialDidLoad:(AmazonAdInterstitial *)interstitial
{
    NSLog(@"Interstial loaded.");
    self.loadStatusLabel.text = @"Interstitial loaded.";
}

- (void)interstitialDidFailToLoad:(AmazonAdInterstitial *)interstitial withError:(AmazonAdError *)error
{
    NSLog(@"Interstitial failed to load.");
    self.loadStatusLabel.text = @"Interstitial failed to load.";
}

- (void)interstitialWillPresent:(AmazonAdInterstitial *)interstitial
{
    NSLog(@"Interstitial will be presented.");
}

- (void)interstitialDidPresent:(AmazonAdInterstitial *)interstitial
{
    NSLog(@"Interstitial has been presented.");
}

- (void)interstitialWillDismiss:(AmazonAdInterstitial *)interstitial
{
    NSLog(@"Interstitial will be dismissed.");
}

- (void)interstitialDidDismiss:(AmazonAdInterstitial *)interstitial
{
    NSLog(@"Interstitial has been dismissed.");
    self.loadStatusLabel.text = @"No interstitial loaded.";
}

Adding Modeless Interstitial Ads through Objective-C Code

To retrieve and display a modeless interstitial ad, you will use an instance of AmazonAdModelessInterstitial. To load a modeless interstitial, call the AmazonAdModelessInterstitial load: method, which uses a background thread to request a modeless interstitial from the Amazon Mobile Ad Network. Only one modeless interstitial can be loading for a given AmazonAdModelessInterstitial instance at a given time. When loading a modeless interstitial, you can also set a number of optional targeting parameters; these are covered on the Ad Targeting Options Page. Once loaded, modelessInterstitialDidLoad callback is fired and the ad is ready for showing. AmazonAdModelessInterstitial also provides the isReady property to check the readiness of the modeless interstitial for convenience. You must call AmazonAdModelessInterstitial onPresented when the modeless interstitial is presented on the screen for impression counting. You must also call AmazonAdModelessInterstitial onHidden to inform the SDK when the modeless interstitial leaves the screen. Below is a code excerpt from SwipeableModelessInterstitialAd on loading, presenting and hiding a modeless interstitial with callback implementations:

(void)loadModelessInterstitial
{
    // Create the interstitial page view
    if (!self.interstitialPageView) {
        self.interstitialPageView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height)];
    }

    // Create the modeless interstitial object
    if (!self.modelessInterstitial) {
        self.modelessInterstitial = [AmazonAdModelessInterstitial modelessInterstitialWithContainerView:self.interstitialPageView];
        self.modelessInterstitial.delegate = self;
    }

    // Load a modeless interstitial ad
    AmazonAdOptions *options = [AmazonAdOptions options];
    options.isTestRequest = YES;
    [self.modelessInterstitial load:options];
}

- (void)updateScrollView
{
    ...

        // If we are moving the modeless interstitial off the screen, call onHidden
        if (self.pageIndex == self.interstitialIndex) {
            [self.modelessInterstitial onHidden];
        }

        // If we are moving the modeless interstitial onto the screen, call onPresented
        if (tmpIndex == self.interstitialIndex) {
            if (![self.modelessInterstitial onPresented]) {
                NSLog(@"Modeless interstitial failed to present");
            }
        }

    ...
}

#pragma mark - AmazonAdModelessInterstitialDelegate

- (UIViewController *)viewControllerForPresentingModalView
{
    return self;
}

- (void)modelessInterstitialDidLoad:(AmazonAdModelessInterstitial *)interstitial
{
    // After the modeless interstitial has been loaded, insert it a couple of pages apart from the page currently on screen

    if (self.interstitialIndex == -1) {
        NSInteger index = self.pageIndex + 2;
        if (index > self.pages.count - 1) {
            index = index - (self.pages.count - 1);
        }

        [self insertInterstitialAtIndex:index];
    }
}

- (void)modelessInterstitialDidFailToLoad:(AmazonAdModelessInterstitial *)interstitial withError:(AmazonAdError *)error
{
    NSLog(@"Modeless interstitial failed to load: %@", error.errorDescription);
}

- (void)modelessInterstitialDidExpire:(AmazonAdModelessInterstitial *)interstitial
{
    NSLog(@"Modeless interstitial has expired");
}     

Optional - Set an Ad Request Timeout Value

An ad request call has a default timeout of 10 seconds. After the timeout threshold is exceeded the adDidFailToLoad callback is called. The default timeout value can be changed using the AmazonAdOptions timeout property, which takes seconds as an argument.

Example:

AmazonAdOptions *options = [AmazonAdOptions options];
options.timeout = 20; // 20 seconds

Where Do I Go From Here?

Compile and run one or more of the sample apps located in IOS sample apps.