MPNativeAdRenderer /5.0.0

@protocol MPNativeAdRenderer <NSObject>

The MoPub SDK has a concept of native ad renderer that allows you to render the ad however you want. It also gives you the ability to expose configurable properties through renderer settings objects to the application that influence how you render your native mediation adapter’s view.

Your renderer should implement this protocol. Your renderer is responsible for rendering the network’s ad data into a view when -retrieveViewWithAdapter:error:1 is called. Your renderer will be asked to render the native ad if your renderer configuration indicates that your renderer supports your specific native ad network.

Finally, your renderer will live as long as the ad adapter so you may store data in your renderer if necessary.

Public Properties

MPNativeViewSizeHandler/viewSizeHandler /+5.0.0

  • Description: The viewSizeHandler is used to allow the app to configure its native ad view size given a maximum width when using ad placer solutions. This is not called when the app is manually integrating native ads. Obtain the renderer’s viewSizeHandler from the settings object in -initWithRendererSettings:.

  • Declaration:

    @optional
    @property (readonly, nonatomic) MPNativeViewSizeHandler viewSizeHandler;
    
  • Parameters: None.

Public Methods

+/rendererConfigurationWithRendererSettings: /+5.0.0

  • Description: You must construct and return an MPNativeAdRendererConfiguration object specific for your renderer. You must set all the properties on the configuration object. Returns a configuration object that allows the MoPub SDK to instantiate your renderer with the application settings and for the supported ad types.

  • Declaration:

    + (MPNativeAdRendererConfiguration *)rendererConfigurationWithRendererSettings:
        (id<MPNativeAdRendererSettings>)rendererSettings;
    
  • Parameters:

    • rendererSettings: Application defined settings that you should store in the configuration object that you construct.

-/initWithRendererSettings: /+5.0.0

  • Description: This is the init method that will be called when the MoPub SDK initializes your renderer.

  • Declaration:

    - (instancetype)initWithRendererSettings:
        (id<MPNativeAdRendererSettings>)rendererSettings;
    
  • Parameters:

    • rendererSettings: The renderer settings object that corresponds to your renderer.
    • parameter: DESCRIPTION_or_None_ABOVE_IF_NONE

-/retrieveViewWithAdapter:error: /+5.0.0

  • Description: You must return a native ad view when -retrieveViewWithAdapter:error: is called. Ideally, you should create a native view each time this is called as holding onto the view may end up consuming a lot of memory when many ads are being shown. However, it is OK to hold a strong reference to the view if you must. If successful, the method will return a native view presenting the ad. If it is unsuccessful at retrieving a view, it will return nil and create an error object for the error parameter.

  • Declaration:

    - (UIView *)retrieveViewWithAdapter:(id<MPNativeAdAdapter>)adapter
                                error:(NSError **)error;
    
  • Parameters:

    • adapter: Your mediation adapter’s adapter class that contains the network specific data necessary to render the ad to a view.

    • error: If you can’t construct a view for whatever reason, you must fill in this error object.

-/adViewWillMoveToSuperview: /+5.0.0

  • Description: The MoPubSDK will notify your renderer when your native ad’s view has moved in the hierarchy. superview will be nil if the native ad’s view has been removed from the view hierarchy. The view your renderer creates is attached to another view before being added to the view hierarchy. As a result, the superview argument will not be the renderer’s ad view’s superview.

  • Declaration:

    - (void)adViewWillMoveToSuperview:(UIView *)superview;
    
  • Parameters:

    • superview: The app’s view that contains the native ad view. There is an intermediate view between the renderer’s ad view and the app’s view.

-/nativeAdTapped /+5.0.0

  • Description: The MoPubSDK will call this method when the user has tapped the ad and will invoke the clickthrough action.

  • Declaration:

    - (void)nativeAdTapped;
    
  • Parameters: None.

Last updated July 10, 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.)