MPCollectionViewAdPlacer

@interface MPCollectionViewAdPlacer : NSObject <MPMoPubAdPlacer>

The MPCollectionViewAdPlacer class enables you to request native ads from the MoPub ad server and place them into a UICollectionView object.

When an instance of this class is initialized with a collection view, it wraps the collection view’s data source and delegate in order to insert ads and adjust the positions of your regular content cells.

Public Methods

Initializing a Collection View Ad Placer

+/placerWithCollectionView:viewController:rendererConfigurations:

  • Description: Creates and returns an ad placer that will insert ads into a collection view at positions that can be configured dynamically on the MoPub website. When you make an ad request, the ad placer will ask the MoPub ad server for the positions where ads should be inserted into the collection view. You can configure these positioning values by editing your ad unit’s settings on the MoPub website. Using this method is equivalent to calling +placerWithCollectionView:viewController:adPositioning:defaultAdRenderingClass: and passing in an MPServerAdPositioning object as the positioning parameter.

  • Declaration:

    + (instancetype)placerWithCollectionView:(UICollectionView *)collectionView
                            viewController:(UIViewController *)controller
                    rendererConfigurations:(NSArray *)rendererConfigurations;
    
  • Parameters:

    • collectionView: The collection view in which to insert ads.

    • controller: The view controller which should be used to present modal content.

    • rendererConfigurations: An array of MPNativeAdRendererConfiguration objects that control how the native ad is rendered.

+/placerWithCollectionView:viewController:adPositioning:rendererConfigurations:

  • Description: Creates and returns an ad placer that will insert ads into a collection view. When using this method, there are two options for controlling the positions where ads appear within the collection view.

    First, you may pass an MPServerAdPositioning object as the positioning parameter, which tells the ad placer to obtain positioning information dynamically from the ad server, which you can configure on the MoPub website. In many cases, this is the preferred approach, since it allows you to modify the positions without rebuilding your application. Note that calling the convenience method +placerWithCollectionView:viewController:defaultAdRenderingClass: accomplishes this as well.

    Alternatively, if you wish to hard-code your positions, you may pass an MPClientAdPositioning object instead.

    Returns an MPCollectionViewAdPlacer object.

  • Declaration:

    + (instancetype)placerWithCollectionView:(UICollectionView *)collectionView
                            viewController:(UIViewController *)controller
                             adPositioning:(MPAdPositioning *)positioning
                    rendererConfigurations:(NSArray *)rendererConfigurations;
    
  • Parameters:

    • collectionView: The collection view in which to insert ads.

    • controller: The view controller which should be used to present modal content.

    • positioning: The positioning object that specifies where ads should be shown in the stream.

    • rendererConfigurations: An array of MPNativeAdRendererConfiguration objects that control how the native ad is rendered.

Requesting Ads

-/loadAdsForAdUnitID:

  • Description: Requests ads from the MoPub ad server using the specified ad unit ID.

  • Declaration:

    - (void)loadAdsForAdUnitID:(NSString *)adUnitID;
    
  • Parameters:

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

-/loadAdsForAdUnitID:targeting:

  • Description: Requests ads from the MoPub ad server using the specified ad unit ID and targeting parameters.

  • Declaration:

    - (void)loadAdsForAdUnitID:(NSString *)adUnitID
                   targeting:(MPNativeAdRequestTargeting *)targeting;
    
  • Parameters:

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

    • targeting: An object containing targeting information, such as geolocation data.

Last updated February 27, 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.)