MPNativeAdAdapter /5.0.0

@protocol MPNativeAdAdapter <NSObject>

The MPNativeAdAdapter protocol allows the MoPub SDK to interact with native ad objects obtained from third-party ad networks. An object that adopts this protocol acts as a wrapper for a native ad object, translating its proprietary interface into a common one that the MoPub SDK can understand.

An object that adopts this protocol must implement the properties property to specify a dictionary of assets, such as title and text, that should be rendered as part of a native ad. When possible, you should place values in the returned dictionary so that they correspond to the predefined keys in the MPNativeAdConstants header file.

An adopting object must additionally implement -displayContentForURL:rootViewController:completion: to supply the behavior that should occur when the user interacts with the ad. Optional methods of the protocol allow the adopting object to define when and how impressions and interactions should be tracked.

Public Properties

Ad Resources

NSDictionary/properties /+5.0.0

  • Description: Provides a dictionary of all publicly accessible assets (such as title and text) for the native ad. When possible, place values in the returned dictionary so that they correspond to the predefined keys in the MPNativeAdConstants header file.

  • Declaration:

    @required
    @property (readonly, nonatomic) NSDictionary *properties;
    
  • Parameters: None.

NSURL/defaultActionURL /+5.0.0

  • Description: The default click-through URL for the ad. This may safely be set to nil if your network doesn’t expose this value (for example, it may only provide a method to handle a click, lacking another for retrieving the URL itself).

  • Declaration:

    @required
    @property (readonly, nonatomic) NSURL *defaultActionURL;
    
  • Parameters: None.

Handling Ad Interactions

/delegate /+5.0.0

  • Description: The MPNativeAdAdapterDelegate to send messages to as events occur. The delegate object defines several methods that you should call in order to inform MoPub of interactions with the ad. This delegate needs to be implemented if third-party impression or click tracking is enabled.

  • Declaration:

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

Public Methods

Handling Ad Interactions

-/displayContentForURL:rootViewController: /+5.0.0

  • Description: Tells the object to open the specified URL using an appropriate mechanism. Your implementation of this method should either forward the request to the underlying third-party ad object (if it has built-in support for handling ad interactions), or open an in-application modal web browser or a modal App Store controller.

  • Declaration:

    - (void)displayContentForURL:(NSURL *)URL
            rootViewController:(UIViewController *)controller;
    
  • Parameters:

    • URL: The URL to be opened.
    • controller: The view controller that should be used to present the modal view controller.

-/enableThirdPartyClickTracking /+5.0.0

  • Description: Determines whether MPNativeAd should track clicks. If not implemented, this will be assumed to return NO, and MPNativeAd will track clicks. If this returns YES, then MPNativeAd will defer to the MPNativeAdAdapterDelegate callbacks to track clicks.

  • Declaration:

    - (BOOL)enableThirdPartyClickTracking;
    
  • Parameters: None.

-/trackClick /+5.0.0

  • Description: Tracks a click for this ad. To avoid reporting discrepancies, only implement this method if the third-party ad network requires clicks to be reported manually.

  • Declaration:

    - (void)trackClick;
    
  • Parameters: None.

Responding to an Ad Being Attached to a View

-/willAttachToView: /+5.0.0

  • Description: This method will be called when your ad’s content is about to be loaded into a view. Implement this method if the underlying third-party ad object needs to be informed of this event.

  • Declaration:

    - (void)willAttachToView:(UIView *)view;
    
  • Parameters:

    • view: A view that will contain the ad content.

-/willAttachToView:withAdContentViews: /+5.0.0

  • Description: This method will be called when your ad’s content is about to be loaded into a view; subviews that contain ad contents are also included. If both this method and willAttachToView: are implemented, only this method will be called. Implement this method if the underlying third-party ad object needs to be informed of this event.

  • Declaration:

    - (void)willAttachToView:(UIView *)view
        withAdContentViews:(NSArray *)adContentViews;
    
  • Parameters:

    • view: A view that will contain the ad content.
    • adContentViews: Array of views that contains the ad’s content views.

-/displayContentForDAAIconTap /+5.0.0

  • Description: This method will be called if your implementation provides a privacy icon through the properties dictionary and the user has tapped the icon.

  • Declaration:

    - (void)displayContentForDAAIconTap;
    
  • Parameters: None.

-/privacyInformationIconView /+5.0.0

  • Description: Returns your ad’s privacy information icon view. Implement this method if your ad supplies its own view for its privacy information icon.

  • Declaration:

    - (UIView *)privacyInformationIconView;
    
  • Parameters: None.

-/mainMediaView /+5.0.0

  • Description: Returns your ad’s main media view. Implement this method if your ad supplies its own view for the main media view, which is typically an image or video. If you implement this method, the SDK will not make any other attempts at retrieving the main media asset.

  • Declaration:

    - (UIView *)mainMediaView;
    
  • Parameters: None.

-/iconMediaView /+5.2.0

  • Description: Returns your ad’s icon view. Implement this method if your ad supplies its own view for the icon view, which is typically an image. If you implement this method, the SDK will not make any other attempts at retrieving the icon asset.

  • Declaration:

    - (UIView *)iconMediaView;
    
  • 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.)