iOS Developer Library

Developer

iAd Framework Reference UIViewController iAd Additions Reference

Options
Deployment Target:

On This Page
Language:

UIViewController

This category on UIViewController provides an interface for configuring the kind of ads that should be shown associated with the view controller's content. Two types of ads may be shown—banner ads and interstitial ads. Banner ads are displayed below the content. While a banner ad is being displayed, the content is resized appropriately based on the size of the banner. Interstitial ads are displayed at a moment in time, and take over the entire screen. Interstitial ads can be displayed automatically or upon request. Automatic display of interstitial ads is tied to the appearance of a view, with the frequency of presentation managed by the framework. On-request display of interstitial ads is also subject to frequency constraints—you should be prepared for a request to display an interstitial ad manually to fail.

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import iAd

Objective-C

@import iAd;

Availability


Available in iOS 7.0 and later.
  • A boolean value that indicates whether the view controller is configured to display banner ads.

    Declaration

    Swift

    var canDisplayBannerAds: Bool

    Objective-C

    @property(nonatomic, assign) BOOL canDisplayBannerAds

    Discussion

    Set this value to YEStrue to enable the display of banner ads in a view controller.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • The originally configured content view of the view controller before banner ads were enabled.

    Declaration

    Swift

    var originalContentView: UIView! { get }

    Objective-C

    @property(nonatomic, retain, readonly) UIView *originalContentView

    Discussion

    Apps that use banner views with a view controller should use this property to access the view controller’s content view.

    When a view controller enables banner ads, the system puts the view controller’s content view inside of a new content view that the system manages. This allows the system to dynamically resize the original content view when a banner ad is displayed, as well as managing the display of the banner ad itself. This property provides access to the original content view, rather than the containing view that manages banner ad display.

    If banner ad display has not been enabled for a view controller, this property returns the content view.

    If banner ad display is enabled and then later disabled for a view controller, the system-managed content view is not removed.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • A boolean value that indicates whether the view controller is displaying a full-screen ad.

    Declaration

    Swift

    var presentingFullScreenAd: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isPresentingFullScreenAd) BOOL presentingFullScreenAd

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • A boolean value that indicates whether the view controller is displaying a banner ad.

    Declaration

    Swift

    var displayingBannerAd: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isDisplayingBannerAd) BOOL displayingBannerAd

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • Prepares the framework to display interstitial ads, which may involve prefetching ad assets.

    Declaration

    Swift

    class func prepareInterstitialAds()

    Objective-C

    + (void)prepareInterstitialAds

    Discussion

    Because displaying an ad involves downloading ad assets over the network, in can sometimes be useful to tell the framework to prepare for ad presentation prior to needing to display the first ad. If there is a point in the launch of your app when it would be convenient to prefetch ad assets, you can use this method to trigger one.

    If this method is not called, the first fetch will occur when a view controller's interstitialPresentationPolicy is set to something other than ADInterstitialPresentationPolicyNone.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • Determines whether interstitials should be presented at all and whether the framework or app should manage the presentation.

    Declaration

    Swift

    var interstitialPresentationPolicy: ADInterstitialPresentationPolicy

    Objective-C

    @property(nonatomic, assign) ADInterstitialPresentationPolicy interstitialPresentationPolicy

    Discussion

    The default presentation policy for a view controller is ADInterstitialPresentationPolicyNone. To enable any presentation of interstitial ads the presentation policy must be set to ADInterstitialPresentationPolicyAutomatic or ADInterstitialPresentationPolicyManual.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • Asks the framework to display an interstitial ad.

    Declaration

    Swift

    func requestInterstitialAdPresentation() -> Bool

    Objective-C

    - (BOOL)requestInterstitialAdPresentation

    Return Value

    YEStrue if an interstitial ad will be displayed, NOfalse otherwise.

    Discussion

    This method can be called at any time to request an ad. If an ad is available, the framework presents it immediately. If there is no ad available, nothing happens.

    Use this method along with a presentation style of ADInterstitialPresentationPolicyManual for a view controller that is on screen for long periods of time and internally manages significant state changes, such as game levels. This allows you to decide precisely when it’s possible for an ad to appear in your app.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • Returns whether an interstitial ad should be displayed.

    Declaration

    Swift

    var shouldPresentInterstitialAd: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL shouldPresentInterstitialAd

    Return Value

    YEStrue if the interstitial ad should be displayed now, NOfalse to prevent presentation at this time.

    Discussion

    Implement this method on a custom view controller to allow the view controller to selectively prevent presentation of an interstitial ad. When using the automatic presentation policy, the system invokes this method when the framework is about to present an interstitial ad.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.

  • Policy options governing how and when interstitial ads may be presented from a view controller.

    Declaration

    Swift

    enum ADInterstitialPresentationPolicy : Int { case None case Automatic case Manual }

    Objective-C

    typedef enum : NSInteger { ADInterstitialPresentationPolicyNone = 0, ADInterstitialPresentationPolicyAutomatic, ADInterstitialPresentationPolicyManual } ADInterstitialPresentationPolicy;

    Constants

    • None

      ADInterstitialPresentationPolicyNone

      Default policy. No interstitial ad is ever presented from the view controller.

      Available in iOS 7.0 and later.

    • Automatic

      ADInterstitialPresentationPolicyAutomatic

      Automatic policy. The framework determines when an interstitial ad is presented.

      Available in iOS 7.0 and later.

    • Manual

      ADInterstitialPresentationPolicyManual

      Manual policy. The app determines when an interstitial ad should be presented. Use requestInterstitialAdPresentation to request the presentation of an interstitial ad at an appropriate time.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 7.0 and later.