iOS Developer Library

Developer

iAd Framework Reference ADBannerView Class Reference

Options
Deployment Target:

On This Page
Language:

ADBannerView

Inheritance


Import Statement


Swift

import iAd

Objective-C

@import iAd;

Availability


Available in iOS 4.0 and later.

The ADBannerView class provides a view that displays banner advertisements to the user. When the user taps a banner view, the view triggers an action programmed into the advertisement. For example, an advertisement might show a movie, present a modal advertisement, or launch Safari to show a webpage. Your application is notified when an action starts and stops, but does not otherwise interact with the advertisement. You receive revenue when users see new advertisements or trigger their actions.

The banner view’s delegate is called when a banner view cycles to show a new advertisement as well as when the user interacts with the banner view. For example, your delegate typically pauses your application’s activities when a user taps an advertisement and restores those activities when the user finishes interacting with the advertisement.

A banner view must always use one of the standard sizes defined in Content Size Identifiers. This is to ensure that the advertisement is drawn correctly. You configure the banner view’s requiredContentSizeIdentifiers property with the set of possible sizes your view is allowed to use in your application. To change the size of the banner view, do not set the bounds directly; instead set the currentContentSizeIdentifier property to one of the size identifiers included in that set. You can retrieve the actual dimensions that a particular identifier equates to on a specific device by calling the sizeFromBannerContentSizeIdentifier: class method.

Subclassing Notes

The ADBannerView class provides a self-contained view. Your application should not subclass ADBannerView, nor should your application attempt to change the behavior of the banner view. For example, your application should never add subviews to a banner view.

  • Initializes a banner view with the specified ad type.

    Declaration

    Swift

    init!(adType type: ADAdType)

    Objective-C

    - (instancetype)initWithAdType:(ADAdType)type

    Parameters

    type

    The type of banner view to configure the receiver as.

    Return Value

    A newly-configured banner view of the specified ad type.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 6.0 and later.

  • adType adType Property

    The ad type of the banner view.

    Declaration

    Swift

    var adType: ADAdType { get }

    Objective-C

    @property(nonatomic, readonly) ADAdType adType

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 6.0 and later.

  • delegate delegate Property

    The delegate of the banner view.

    Declaration

    Swift

    weak var delegate: ADBannerViewDelegate!

    Objective-C

    @property(nonatomic, weak) id< ADBannerViewDelegate > delegate

    Discussion

    The banner view delegate is notified when events related to the banner view and current ad occur, such as when a new ad is loaded, when errors occur while fetching ads, or when banner actions begin and end.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 4.0 and later.

  • Reserved for future use.

    Declaration

    Swift

    var advertisingSection: String!

    Objective-C

    @property(nonatomic, copy) NSString *advertisingSection

    Discussion

    This property is reserved for future use.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 4.0 and later.

  • A set of identifiers for the sizes of advertisements that the banner view can display.

    Deprecation Statement

    Banner views no longer use content size identifiers. See Content Size Identifiers for details.

    Declaration

    Objective-C

    @property(nonatomic, copy) NSSet *requiredContentSizeIdentifiers

    Discussion

    Banner views must always have dimensions that match the size of a known advertising format. Your application sets the requiredContentSizeIdentifiers property so that the banner view can download advertisements that provide artwork for those sizes. The known sizes are listed in Content Size Identifiers. The default value is a set including both ADBannerContentSizeIdentifierPortrait and ADBannerContentSizeIdentifierLandscape.

    If the set includes a single identifier, then advertisements downloaded by the banner view have a banner image with that size. If the set includes multiple identifiers, advertisements downloaded by the banner view include images for all sizes specified in the set. This allows the banner view to be resized without having to download additional images. Do not include identifiers for sizes that your application does not use, as it may unnecessarily restrict the inventory of advertisements available to your application.

    Setting the requiredContentSizeIdentifiers property does not resize the banner view. To change the size of the banner view, your application sets the currentContentSizeIdentifier property.

    Import Statement

    Objective-C

    @import iAd;

    Availability

    Available in iOS 4.0 and later.

    Deprecated in iOS 6.0.

  • A string that identifies the current size of the advertisement displayed in the banner view.

    Deprecation Statement

    Banner views no longer use content size identifiers. See Content Size Identifiers for details.

    Declaration

    Objective-C

    @property(nonatomic, copy) NSString *currentContentSizeIdentifier

    Discussion

    Your application should never directly change the size of the banner view. Instead, set the currentContentSizeIdentifier property to a known advertising size. The view is automatically resized to match the new content size. The default value is ADBannerContentSizeIdentifierPortrait.

    The identifier placed in the currentContentSizeIdentifier property must be included in the set of identifiers stored in the requiredContentSizeIdentifiers property. This ensures that an advertisement displayed by the view can still be displayed after the view’s size changes. Setting a value not included in the requiredContentSizeIdentifiers property causes an exception to be thrown.

    Import Statement

    Objective-C

    @import iAd;

    Availability

    Available in iOS 4.0 and later.

    Deprecated in iOS 6.0.

  • Converts a banner content size identifier into its physical size.

    Deprecation Statement

    Banner views no longer use content size identifiers. See Content Size Identifiers for details.

    Declaration

    Objective-C

    + (CGSize)sizeFromBannerContentSizeIdentifier:(NSString *)contentSizeIdentifier

    Parameters

    contentSizeIdentifier

    A string that identifies a banner content size. See Content Size Identifiers for possible values.

    Return Value

    The dimensions of that content size in points.

    Discussion

    The return value differs based on the device your application is running on.

    Import Statement

    Objective-C

    @import iAd;

    Availability

    Available in iOS 4.0 and later.

    Deprecated in iOS 6.0.

  • A Boolean value that states whether the banner view has downloaded an advertisement. (read-only)

    Declaration

    Swift

    var bannerLoaded: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isBannerLoaded) BOOL bannerLoaded

    Discussion

    Banner views automatically download new advertisements in the background. This property returns YEStrue if an advertisement is loaded; NOfalse otherwise.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 4.0 and later.

  • A Boolean value that states whether the banner is currently executing an user-triggered action. (read-only)

    Declaration

    Swift

    var bannerViewActionInProgress: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isBannerViewActionInProgress) BOOL bannerViewActionInProgress

    Discussion

    Advertisements have an action that is triggered when the user taps the banner. Some actions remain in the application, covering the application’s user interface until the action completes. The value of this property is YEStrue when such an action is running; otherwise it is NOfalse.

    Your application should avoid polling this property. Instead, implement the delegate methods to detect when an action begins or ends.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 4.0 and later.

  • Cancels an executing banner view action.

    Declaration

    Swift

    func cancelBannerViewAction()

    Objective-C

    - (void)cancelBannerViewAction

    Discussion

    A banner view action can cover your application’s user interface. However, your application continues to run, and receives events normally. If your application receives an event that requires the user’s attention, it can programmatically cancel the action and uncover its interface by calling cancelBannerViewAction. Canceling actions frequently can cause a loss of revenue for your application.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 4.0 and later.

Data Types

  • Error codes for the iAd error domain.

    Declaration

    Swift

    enum ADError : Int { case Unknown case ServerFailure case LoadingThrottled case InventoryUnavailable case ConfigurationError case BannerVisibleWithoutContent case ApplicationInactive case AdUnloaded }

    Objective-C

    typedef enum : NSInteger { ADErrorUnknown = 0, ADErrorServerFailure = 1, ADErrorLoadingThrottled = 2, ADErrorInventoryUnavailable = 3, ADErrorConfigurationError = 4, ADErrorBannerVisibleWithoutContent = 5, ADErrorApplicationInactive = 6 ADErrorAdUnloaded = 7, } ADError;

    Constants

    • Unknown

      ADErrorUnknown

      Indicates that an unknown or unexpected error occurred.

      Available in iOS 4.0 and later.

    • ServerFailure

      ADErrorServerFailure

      Indicates that the connection to the advertisements server failed.

      Available in iOS 4.0 and later.

    • LoadingThrottled

      ADErrorLoadingThrottled

      Indicates that the download from the advertisements server is currently being throttled.

      Available in iOS 4.0 and later.

    • InventoryUnavailable

      ADErrorInventoryUnavailable

      Indicates that no advertisements are currently available to download.

      Available in iOS 4.0 and later.

    • ConfigurationError

      ADErrorConfigurationError

      Indicates that your application has not been configured to receive advertisements. Check your application’s configuration on iTunes Connect. This error is not received when your application is running in Sandbox.

      Available in iOS 4.0 and later.

    • BannerVisibleWithoutContent

      ADErrorBannerVisibleWithoutContent

      Indicates that the banner is visible, but no advertisement is shown. Your application must always hide the banner when it does not have an advertisement to display.

      Available in iOS 4.0 and later.

    • ApplicationInactive

      ADErrorApplicationInactive

      Indicates that ad content is not available because the application is not currently active.

      Available in iOS 4.0 and later.

    • AdUnloaded

      ADErrorAdUnloaded

      The ad being displayed in the banner was unloaded. This might happen when an ad expires or when an ad is moved from a non-visible banner to a visible banner.

      Available in iOS 4.0 and later.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 4.0 and later.

  • These strings are used to identify the size of an advertisement.

    Declaration

    Objective-C

    extern NSString * const ADBannerContentSizeIdentifier320x50; extern NSString * const ADBannerContentSizeIdentifier480x32; extern NSString * const ADBannerContentSizeIdentifierPortrait; extern NSString * const ADBannerContentSizeIdentifierLandscape;

    Constants

    • ADBannerContentSizeIdentifier320x50

      ADBannerContentSizeIdentifier320x50

      Indicates that the banner view is 320 points by 50 points in size. This size is used on iPhone for portrait advertisements.

      Available in iOS 4.0 and later.

      Deprecated in iOS 4.2.

    • ADBannerContentSizeIdentifier480x32

      ADBannerContentSizeIdentifier480x32

      Indicates that the banner view is 480 points by 32 points in size. This size is used on iPhone for landscape advertisements.

      Available in iOS 4.0 and later.

      Deprecated in iOS 4.2.

    • ADBannerContentSizeIdentifierPortrait

      ADBannerContentSizeIdentifierPortrait

      Indicates that the banner view is in portait mode. The exact size of the portait view is dependent on the iOS device the advertisement is displayed on. On iPhone, a portrait banner is 320 points by 50 points in size. On iPad, a portrait banner is 768 points by 66 points in size.

      Available in iOS 4.2 and later.

      Deprecated in iOS 6.0.

    • ADBannerContentSizeIdentifierLandscape

      ADBannerContentSizeIdentifierLandscape

      Indicates that the banner view is in landscape mode. The exact size of the view is dependent on the iOS device the advertisement is displayed on. On iPhone, a landscape banner is 480 points by 32 points in size. On iPad, a landscape banner is 1024 points by 66 points in size.

      Available in iOS 4.2 and later.

      Deprecated in iOS 6.0.

  • This constant defines the iAd framework error domain.

    Declaration

    Swift

    let ADErrorDomain: String

    Objective-C

    extern NSString * const ADErrorDomain;

    Constants

    • ADErrorDomain

      ADErrorDomain

      Indicates an error occurred in iAd.

      Available in iOS 4.0 and later.

  • Constants that indicate the types of ads.

    Declaration

    Swift

    enum ADAdType : Int { case Banner case MediumRectangle }

    Objective-C

    typedef enum : NSInteger, ) { ADAdTypeBanner, ADAdTypeMediumRectangle } ADAdType;

    Constants

    • Banner

      ADAdTypeBanner

      A device-width banner ad.

      The banner height varies with device type and orientation as follows:

      UI Idiom and Orientation

      Ad Height

      phone, portrait

      50 points

      phone, landscape

      32 points

      pad, portrait or landscape

      66 points

      Available in iOS 6.0 and later.

    • MediumRectangle

      ADAdTypeMediumRectangle

      A pad-only 320x250 point ad, based on the International Advertising Bureau’s “Medium Rectangle” Interactive Marketing Unit.

      Available in iOS 6.0 and later.

    Import Statement

    Objective-C

    @import iAd;

    Swift

    import iAd

    Availability

    Available in iOS 6.0 and later.