Using the iAd Service
Go Up to Creating an iOS App
Advertising services enable you to display ads in your applications to gain some income. iAd is the advertising service of Apple for iOS. This topic describes how to place ads from iAd in your applications using FireMonkey.
- Note: Read iOS Mobile Application Development before you continue. The following information complements the main documentation topic about iOS development.
Contents
Supported Devices
FireMonkey supports iAd on any supported iOS device.
Prerequisites
Before you can use the iAd service, in addition to preparing your development environment:
- You must be prepared to code sign iOS applications. See iOS Mobile Application Development, Preparing to Code Sign Your Application.
- When you create an App ID for your application, you must use an explicit app ID that is specific to a single application; for example:
com.mycompany.myapp
. You cannot use a wildcard app ID such ascom.mycompany.*
.
- When you create an App ID for your application, you must use an explicit app ID that is specific to a single application; for example:
- You must have an iAd App Network contract with Apple in place. Follow the steps described in iAd App Network.
Configuring Your Application for iAd in iTunes Connect
- To use and test the iAd service in your application, you must first create an entry for your application in iTunes Connect.
- After you have an entry for your application, open the Manage Your Apps module of iTunes Connect and open the App Summary page of your application.
- Click Set Up iAd Network on the right-hand side of the App Summary page.
- Then click Enable iAds and click Save.
Adding iAd Support to Your Mobile Apps
Here is the general procedure for adding iAd ads to your multi-device applications on iOS:
- Add an instance of the TBannerAd component to your application.
- Configure TBannerAd to load an ad from iAd.
- Handle how your user interacts with this ad.
Loading an Ad
To display an ad from your advertising service in your application, load an ad from your service.
Loading an Ad from Your Advertising Service
To load an ad from your advertising service, call LoadAd. The LoadAd procedure is asynchronous, and when it finishes, it triggers one of the following events:
- OnDidFail is triggered if there is an error. OnDidFail provides a parameter,
Error
, that provides detailed information about the error that prevented the banner from loading an ad. - OnDidLoad is triggered if the request is successful.
You usually want to call LoadAd from a form event such as OnShow, to load an ad as soon as the form is displayed.
Handling User Interaction with Ads
When your user taps an ad, this triggers an action. This action typically consists of a full-screen version of the ad, or of opening a URL on a Web browser.
Between your user tapping the ad and the triggered action, TBannerAd triggers its OnActionCanBegin event. Handle this event to decide whether or not you want to let the action happen.
You might also want to use your handler for the OnActionCanBegin event to pause some running features of your applications, to avoid wasting processing during the ad action. Then you can define an event handler for the OnActionDidFinish event where you resume these features of your application.
Canceling an Ad Action at Any Time
When your user taps an ad, this triggers an action. This action typically consists either of a full-screen version of the ad, or of opening a URL on a Web browser. See Handling User Interaction with Ads.
At any point, if your application requires your user attention, you can check if there is an ad action in progress, and you can stop this action:
Delphi:
if MyBannerAd.IsActionInProgress then
MyBannerAd.CancelAction;
C++:
if (MyBannerAd->IsActionInProgress())
MyBannerAd->CancelAction();
- Note: Canceling ad actions affects your revenue from advertisement. For more information, see the Apple documentation.
Testing Your iAds
The iAd service automatically displays test or real ads depending on how you built your application:
- When you deploy your application for ad hoc distribution or simply run your application, ads are test ads.
- When you deploy your application for submission to the App Store, ads are real ads.
Troubleshooting Loading an Ad from iAd
The following table lists some problems that prevent your application from showing an ad, and potential solutions:
Cause | Description | Recommendation |
---|---|---|
Network error |
No network connectivity to the ad server |
Verify your Wi-Fi or data connection |
Internal server error |
An invalid response was received from the ad server |
-- |
Lack of ad inventory |
No ads are currently available to download from the ad server |
-- |
Wrong application configuration |
Ad service configuration parameters of your application are wrong |
Configure your application for iAd in iTunes Connect |