Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Using the iAd Adobe AIR native extension for iOS

by Alex Liebert

Alex Liebert
  • Milkman Games

Content

  • Setting up iAds in iTunes Connect
  • Including the IAdAPI library
  • Getting started with the API and banner ads
  • Showing interstitial ads
  • Updating your application descriptor file
  • Building the application
  • Troubleshooting
  • Where to go from here

Created

15 May 2012

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR advertising Flash Builder Flash Professional gaming iOS Native extensions

Requirements

Prerequisite knowledge

Experience building games for iOS with Flash Builder and Adobe AIR will help you make the most of this article.

 

Additional required other products

  • Milkman Games iAd Extension for iOS

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Adobe AIR SDK

With the iAd Extension for iOS from Milkman Games, you can rapidly integrate advertisements from the Apple iAd Network into your mobile AIR application using ActionScript 3.

The iAd Extension for iOS is a completely native iAd solution implemented to Apple specifications that enables you to:

  • Monetize free games via Apple's iAd Network
  • Display your first ad with just two lines of code
  • Jumpstart development with a complete sample application, ActionScript 3 documentation, and a getting started guide
  • Support iAd banner formats for iPad, iPhone, and iPod Touch
  • Reposition ads automatically when your app changes orientation
  • Create, destroy, show, and hide ads with simple commands
  • Support lucrative interstitial ads on iPad

This tutorial provides details on getting started with the iAd Extension for iOS. If you want to follow all the steps below, you'll need to purchase and download the iAd Extension for iOS.

Setting up iAds in iTunes Connect

You'll need to set up iAd for your apps inside iTunes Connect before you can use the extension. Follow these steps:

  1. Log into the Apple Developer center at http://developer.apple.com and go to the iOS Developer area.
  2. Click iTunes Connect on the right.
  3. Before you can use the iAd Network in your apps, you must read and agree to Apple's Developer Advertising Services Agreement. In iTunes Connect, click Contracts, Tax, and Banking and then click Request to the right of iAd Network (see Figure 1). Follow the on-screen instructions.
Figure 1. Requesting the iAd Network contract.
Figure 1. Requesting the iAd Network contract.
  1. Click Manage Your Applications.

Note: If your app is already configured in iTunes Connect, select it and skip to step 13 below.

  1. Click Add New App.
Figure 2. Adding information for the new app.
Figure 2. Adding information for the new app.
  1. Select a default language and then type a Name and SKU Number for your application (see Figure 2). Under Bundle ID, click You Can Register A New Bundle ID Here, which will bring you to the Provisioning Portal.
  2. In the Provisioning Portal, click New App ID (see Figure 3).
Figure 3. Adding a new App ID.
Figure 3. Adding a new App ID.
  1. Type a description for your new app. For Bundle Identifier, type a unique name in the recommended scheme (like com.yourcompany.YourGameName).

Note: Take note of what you type here, as you'll need to match it exactly in your application descriptor file.

  1. Click Submit and close the Provisioning Portal. Back on the App Information page, select the Bundle ID you just created. If you don't see your new Bundle ID listed, refresh the page or cancel the operation and click New App again.
  2. Click Continue.
  3. Continue through the next couple of steps, entering the release date, pricing tier, version information, rating information, metadata, icons, screenshots, and other required data for your application. If you're just creating a test app, you can set the release date far in the future. At least one screenshot and icon are required to register an application. If you need some dummy images to test with, you can find them in the /tutorialimages folder included with the iAd Native Extension zip package from Milkman Games.
  4. Click Save.
  5. On the iTunes Connect screen for your app, click Set Up iAd Network.
  6. Click Enable iAds and select a primary target audience (see Figure 4).
Figure 4. Enabling iAd advertising.
Figure 4. Enabling iAd advertising.
  1. Click Save.

You're now ready to start building an iAd enabled AIR application.

Including the IAdAPI library

The next step is to add the com.milkmangames.nativeextensions.IAd.ane library to your project. (If you are not using Flash Builder 4.6 and later or Flash Professional CS6 and later you will need to add the IadAPI.swc library instead.)

These files can be found in the /extension folder of the extension package zip file.

In Flash Professional CS6:

  1. Create a new project of the type AIR for iOS.
  2. Choose File > Publish Settings.
  3. Click the wrench icon next to Script for ActionScript Settings.
  4. Select the Library Path tab.
  5. Click Browse for Native Extension (ANE) File select the com.milkmangames.nativeextensions.IAd.ane file.

In Flash Builder 4.6:

  1. Go to Project Properties (right-click your project in Package Explorer and select Properties).
  2. Select ActionScript Build Path and click the Native Extensions tab.
  3. Click Add ANE and navigate to the com.milkmangames.nativeextensions.IAd.ane file.

In FlashDevelop:

  1. Copy the IAdAPI.swc file to your project folder.
  2. In the explorer panel, right-click the SWC and select Add To Library.
  3. Right-click the SWC file in the explorer panel again, select Options, and then select External Library.

Getting started with the API and banner ads

You can get the iAd Extension for iOS up and running with a few simple calls. See example/IAdExample.as for a full example that shows how to create and destroy ads, set visibility, handle errors, and more.

  1. Start by importing the API Classes:
com.milkmangames.nativeextensions.ios.*; com.milkmangames.nativeextensions.ios.events.*;
  1. Next, initialize the API and create an instance of the IAd object:
var iAd:IAd=IAd.create();
  1. Check if the device will support iAd ads. Although AIR apps will run on iOS 4.0 and later, iAd support is only available in iOS 4.2 or later.
if(!IAd.iAd.isIAdAvailable()) { trace(“this device doesn't have iAd support.”); return; }
  1. Create a Banner Ad container, and listen for the appropriate events. You should listen for all the relevant error events listed below, to be sure all error events are caught. After the call to createBannerAd(), the extension will automatically handle the lifecycle of banner ads. Specifically, it will automatically try to get a new ad after one fails to load, automatically show a new ad when one is ready, and automatically hide the ad view when there's a problem—all in accordance with Apple requirements.

The following example code creates a banner ad container at the top of the screen that can show either portrait or landscape content.

// Listen for events. IAd.iAd.addEventListener(IAdEvent.BANNER_ACTION_BEGIN,onBannerActionBegin); IAd.iAd.addEventListener(IAdEvent.BANNER_ACTION_FINISHED,onBannerActionFinished); IAd.iAd.addEventListener(IAdEvent.BANNER_AD_LOADED,onBannerAdLoaded); IAd.iAd.addEventListener(IAdErrorEvent.BANNER_AD_FAILED,onBannerAdFailed); // create a banner ad container at the top of the screen Iad.iAd.createBannerAd(IAdBannerAlignment.TOP, IAdContentSize.PORTRAIT_OR_LANDSCAPE);
  1. When a user clicks on one of the banner ads in your application, either they will be taken out of your application to the App Store or Safari, or they will be shown a full screen pop-up ad. In the case of a pop-up ad, you'll want to stop sounds in your application and pause any major actions. You can tell whether the user is going to be viewing a pop-up or leaving the application by the event's willLeaveApplication property:
private function onBannerActionBegin(e:IAdEvent):void { trace(“the user started interacting with an ad.”); if(e.willLeaveApplication) { // the app is about to exit to go somewhere else. } else { // the user is going to see a full screen popup. Stop sound and pause. this.didPauseForAd=true; pauseApplication(); stopSounds(); } }
  1. When the user is done with the ad, they may be returned to your application. If you had paused actions and sounds in the previous event, you'll want to resume them when the interaction is over:
private function onBannerActionFinished(e:IAdEvent):void { trace(“the user finished interacting with an ad.”); if(this.didPauseForAd) { // we had paused for the ad, now we're back, so resume this.didPauseForAd=false; resumeApplication(); resumeSounds(); } }
  1. You may want to hide or show an ad area based on the application state. For instance, you might want to show ads most of the time, but hide them when the user is viewing a special menu (and then show them again later). This is easily done with the setBannerVisibility() method. The first parameter, visibility , shows the ad when true and hides it when false . When the second parameter, withAnimation , is true the ad will slide on to and off of the screen with an animated effect.
private function onBannerActionBegin(e:IAdEvent):void { trace(“the user started interacting with an ad.”); if(e.willLeaveApplication) { // the app is about to exit to go somewhere else. } else { // the user is going to see a full screen popup. Stop sound and pause. this.didPauseForAd=true; pauseApplication(); stopSounds(); } }

Showing interstitial ads

In addition to banner ads, you may be able to show a special type of ad known as an interstitial ad. These ads only work on iPads running iOS Version 4.3 or later.

Interstitial ads take up the full screen until the user is done with them. As a result, they are typically more lucrative than banner ads. Interstitial ads are most often used between two parts of your app; for instance, an interstitial ad may be shown after one game finishes, before the user can play another game.

Follow these steps to display an interstitial ad:

  1. First make sure you're listening for the interstitial ad events, and then call showInterstitial().
// listen for events! IAd.iAd.addEventListener(IAdEvent.INTERSTITIAL_ACTION_BEGIN,onInterstitialActionBegin) IAd.iAd.addEventListener(IAdEvent.INTERSTITIAL_ACTION_FINISHED,onInterstitialActionFinished); IAd.iAd.addEventListener(IAdEvent.INTERSTITIAL_AD_LOADED,onInterstitialAdLoaded); IAd.iAd.addEventListener(IAdEvent.INTERSTITIAL_AD_UNLOADED,onInterstitialAdUnloaded); IAd.iAd.addEventListener(IAdErrorEvent.INTERSTITIAL_AD_FAILED,onInterstitialAdFailed); // show the interstitial IAd.iAd.showInterstitial();
  1. If the iAd object succeeds in loading an interstitial ad, it will trigger the IAdEvent.INTERSTITIAL_AD_LOADED event. The iPad's screen will now be covered completely by the ad, and the app should stop any sounds until the ad is done. If there's an error and the iAd object can't get an interstitial ad, it will trigger IAdErrorEvent.INTERSTITIAL_AD_FAILED. Finally, the IAdEvent.INTERSTITIAL_AD_UNLOADED event will fire when the ad is being removed from the screen; at that point the app can resume its normal operation.
private function onInterstitialAdLoaded(e:IAdEvent):void { trace(“the interstitial loaded and will show now.”); stopSounds(); } private function onInterstitialAdUnloaded(e:IAdEvent):void { trace(“unloading the interstitial ad.”); resumeSounds(); continueWithApp(); } private function onInterstitialAdFailed(e:IAdErrorEvent):void { trace(“there was an error loading the ad.”); resumeSounds(); continueWithApp(); }

For complete examples of all available methods for interstitial ads, see the IAdExample.as file in the /example folder.

Updating your application descriptor file

In your application descriptor XML file you need to specify the version of the AIR SDK you are using (3.1 or later) as well as a link to the extension. For a working example, see example/app.xml.

  1. If it is not already set, set your AIR SDK version in the application descriptor file (use 3.2 below if you are using that version of the SDK):
<application xmlns="http://ns.adobe.com/air/application/3.1">
  1. Include a link to the extension in the descriptor:
<extensions> <extensionID>com.milkmangames.extensions.IAd</extensionID> </extensions>

Building the application

If you're using Flash Builder 4.6 or later (or /Flash Professional CS6 or later), and have added the iAd extension library as described above, then you can compile as you usually do directly from your IDE. If not and you are building your app with the extension from the command line, then you'll need to specify the directory containing the com.milkmangames.nativeextensions.IAd.ane file.

Here is an example build command line:

[PATH_TO_AIR_SDK]\bin\adt -package -target ipa-test-interpreter -storetype pkcs12 –keystore [YOUR_KEYSTORE_FILE] -storepass [YOUR_PASSWORD] -provisioning-profile [YOUR_MOBILEPROVISION_FILE] iadapp.ipa app.xml iadexample.swf -extdir [DIRECTORY_CONTAINING_ANE_FILE]

When you're building a version of your app for testing be sure you use the development version of the .mobileprovision file

You can and should use the distribution version of the .mobileprovision file when building the release version of your app to upload to the App Store.

Troubleshooting

Use the tips below to troubleshoot any problems you may be having with the iAd Extension for iOS:

  • If the Enable Ads Button is not present in iTunes Connect, make sure you've agreed to Apple's iAd contract in the Contracts section.
  • If you're adding iAd support to an already published game, you need to create a new version, and enable iAd on that new version. Make sure you update the version number appropriately in the new version's application descriptor file.
  • If the test ad starts in portrait mode, even though your app is in landscape mode, that's not unusual for a test ad on some devices. In production, the appropriate ads will always be shown, as long as you've set the correct IAdContentSize settings when calling createBannerAd().

Where to go from here

Now that you have the iAd Extension for iOS up and running, you may want to explore the ActionScript 3 documentation or check out the other tools from available from Milkman Games.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

More Like This

  • What's new in Adobe AIR 3
  • Installation and deployment options in Adobe AIR 3
  • Packaging Adobe AIR applications for the desktop
  • Using Flash Builder 4.5 to package applications for Google Android devices
  • Using Flash Builder 4.5 to package applications for BlackBerry Tablet OS devices
  • Introducing the Adobe AIR security model
  • Adobe AIR Marketplace FAQ
  • Getting started with Adobe AIR for Flex and ActionScript 3 developers
  • Ten tips for building better Adobe AIR applications
  • Uploading images from CameraRoll and CameraUI

Tutorials and samples

Tutorials

  • Using the iOS Simulator to test and debug AIR applications
  • Using the Amazon In-App Purchase Adobe AIR native extension for Android and Kindle Fire
  • Transferring data with AIR native extensions for iOS – Part 3
  • Exchanging Vector and Array objects between ActionScript 3 and C, C++, or Objective-C

Samples

  • Licensing Adobe AIR applications on Android
  • Using web fonts with Adobe AIR 2.5
  • Using Badger for Adobe AIR applications

AIR blogs

More
07/09/2012 Protected: Publishing Adobe AIR 3.0 for TV on Reference Devices
07/08/2012 Source Code: Adobe AIR 3.3 Retina Video Application
07/06/2012 Application specific File Storage on Adobe AIR based ios Application
07/04/2012 Recent Work - iPad/Android App: Inside My toyota

AIR Cookbooks

More
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay
01/20/2012 Skinnable Transform Tool
01/18/2012 Recording webcam video & audio in a flv file on local drive
12/12/2011 Date calculations using 'out-of-the-box' functions

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement