MPAdView

@interface MPAdView : UIView <MPMoPubAd>

The MPAdView class provides a view that can display banner advertisements.

Public Properties

Setting and Getting the Delegate

MPAdViewDelegate/delegate

  • Description: The delegate (MPAdViewDelegate) of the ad view.

  • Declaration:

    @property (readwrite, nonatomic) id<MPAdViewDelegate> delegate;
    
  • Parameters: None.

Setting Request Parameters

NSString/adUnitId

  • Description: The MoPub ad unit ID for this ad view. Ad unit IDs are created on the MoPub website. An ad unit is a defined placement in your application set aside for advertising. If no ad unit ID is set, the ad view will use a default ID that only receives test ads.

  • Declaration:

    @property (readwrite, copy, nonatomic) NSString *adUnitId;
    
  • Parameters: None.

CGSize/maxAdSize

  • Description: The maximum desired ad size. A list of standard ad sizes is available in MPConstants.h.

  • Declaration:

    @property (assign, readwrite, nonatomic) CGSize maxAdSize;
    
  • Parameters: None.

NSString/keywords

  • Description: A string representing a set of non-personally identifiable keywords that should be passed to the MoPub ad server to receive more relevant advertising. Note that if a user is in General Data Protection Regulation (GDPR) region and MoPub doesn’t obtain consent from the user, “keywords” will still be sent to the server.

  • Declaration:

    @property (readwrite, copy, nonatomic) NSString *keywords;
    
  • Parameters: None.

NSString/userDataKeywords

  • Description: A string representing a set of personally identifiable keywords that should be passed to the MoPub ad server to receive more relevant advertising. Keywords are typically used to target ad campaigns at specific user segments. They should be formatted as comma-separated key-value pairs (for example, marital:single,age:24). Refer to our documentation about keyword targeting options. Note that if a user is in General Data Protection Regulation (GDPR) region and MoPub doesn’t obtain consent from the user, “userDataKeywords” will not be sent to the server.

  • Declaration:

    @property (readwrite, copy, nonatomic) NSString *userDataKeywords;
    
  • Parameters: None.

CLLocation/location

  • Description: A CLLocation object representing a user’s location that should be passed to the MoPub ad server to receive more relevant advertising.

  • Declaration:

    @property (readwrite, copy, nonatomic) CLLocation *location;
    
  • Parameters: None.

NSDictionary/localExtras

  • Description: An optional dictionary containing extra local data.

  • Declaration:

    @property (readwrite, copy, nonatomic) NSDictionary *localExtras;
    
  • Parameters: None.

Public Methods

Initializing a Banner Ad

-/initWithAdUnitId:

  • Description: Initializes an MPAdView with the given ad unit ID. Returns a newly initialized ad view corresponding to the given ad unit ID and size.

  • Declaration:

    - (id)initWithAdUnitId:(NSString *)adUnitId;
    
  • Parameters:

    • adUnitId: A string representing a MoPub ad unit ID.

Loading a Banner Ad

-/loadAd

  • Description: Requests a new ad from the MoPub ad server with a maximum desired ad size equal to the size of the current bounds of this view. If the ad view is already loading an ad, this call will be ignored. You may use forceRefreshAd if you would like cancel any existing ad requests and force a new ad to load.

  • Declaration:

    - (void)loadAd;
    
  • Parameters: None.

-/loadAdWithMaxAdSize:

  • Description: Requests a new ad from the MoPub ad server with the specified maximum desired ad size. If the ad view is already loading an ad, this call will be ignored. You may use forceRefreshAd if you would like cancel any existing ad requests and force a new ad to load.

  • Declaration:

    - (void)loadAdWithMaxAdSize:(CGSize)size;
    
  • Parameters:

    • size: The maximum desired ad size to request. You may specify this value manually, or use one of the presets found in MPConstants.h for the most common types of maximum ad sizes. If using kMPPresetMaxAdSizeMatchFrame, the frame will be used as the maximum ad size.

-/forceRefreshAd

  • Description: Cancels any existing ad requests and requests a new ad from the MoPub ad server using the previously loaded maximum desired ad size.

  • Declaration:

    - (void)forceRefreshAd;
    
  • Parameters: None.

Handling Orientation Changes

-/rotateToOrientation:

  • Description: Informs the ad view that the device orientation has changed. Banners from some third-party ad networks have orientation-specific behavior. You should call this method when your application’s orientation changes if you want mediated ads to acknowledge their new orientation. If your application layout needs to change based on the size of the mediated ad, you may want to check the value of adContentViewSize after calling this method, in case the orientation change causes the mediated ad to resize.

  • Declaration:

    - (void)rotateToOrientation:(UIInterfaceOrientation)newOrientation;
    
  • Parameters:

    • newOrientation: The new interface orientation (after orientation changes have occurred).

-/lockNativeAdsToOrientation:

  • Description: Forces third-party native ad networks to only use ads sized for the specified orientation. Banners from some third-party ad networks have orientation-specific behaviors and/or sizes. You may use this method to lock ads to a certain orientation. For instance, if you call this with MPInterfaceOrientationPortrait, native networks will never return ads sized for the landscape orientation. (Refer also to unlockNativeAdsOrientation and allowedNativeAdsOrientation.)

    typedef enum {
            MPNativeAdOrientationAny,
            MPNativeAdOrientationPortrait,
            MPNativeAdOrientationLandscape
        } MPNativeAdOrientation;
    
  • Declaration:

    - (void)lockNativeAdsToOrientation:(MPNativeAdOrientation)orientation;
    
  • Parameters:

    • orientation: An MPNativeAdOrientation enum value.

-/unlockNativeAdsOrientation

  • Description: Allows third-party native ad networks to use ads sized for any orientation. You do not need to call this method unless you have previously called lockNativeAdsToOrientation:. (Refer also to allowedNativeAdsOrientation).

  • Declaration:

    - (void)unlockNativeAdsOrientation;
    
  • Parameters: None.

-/allowedNativeAdsOrientation

  • Description: Returns enum value representing the banner orientations that third-party ad networks are allowed to use. (Refer also to lockNativeAdsToOrientation: and unlockNativeAdsOrientation).

  • Declaration:

    - (MPNativeAdOrientation)allowedNativeAdsOrientation;
    
  • Parameters: None.

Obtaining the Size of the Current Ad

-/adContentViewSize

  • Description: Returns the size of the current underlying mediated ad being displayed in the ad view. Ad sizes may vary between different ad networks. This method returns the actual size of the underlying mediated ad. This size may be different from the original, initialized size of the ad view. You may use this size to determine to adjust the size or positioning of the ad view to avoid clipping or border issues.

  • Declaration:

    - (CGSize)adContentViewSize;
    
  • Parameters: None.

Managing the Automatic Refresh of Ads

-/stopAutomaticallyRefreshingContents

  • Description: Stops the ad view from periodically loading new advertisements. By default, an ad view is allowed to automatically load new advertisements if a refresh interval has been configured on the MoPub website. This method prevents new ads from automatically loading, even if a refresh interval has been specified.

    As a best practice, you should call this method whenever the ad view will be hidden from the user for any period of time, in order to avoid unnecessary ad requests. You can then call startAutomaticallyRefreshingContents to re-enable the refresh behavior when the ad view becomes visible.

  • Declaration:

    - (void)stopAutomaticallyRefreshingContents;
    
  • Parameters: None.

-/startAutomaticallyRefreshingContents

  • Description: Causes the ad view to periodically load new advertisements in accordance with user-defined refresh settings on the MoPub website. Calling this method is only necessary if you have previously stopped the ad view’s refresh behavior using stopAutomaticallyRefreshingContents. By default, an ad view is allowed to automatically load new advertisements if a refresh interval has been configured on the MoPub website. This method has no effect if a refresh interval has not been set.

  • Declaration:

    - (void)startAutomaticallyRefreshingContents;
    
  • Parameters: None.

Last updated February 11, 2020

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2020 MoPub (a division of Twitter, Inc.)