MPNativeCustomEvent

@interface MPNativeCustomEvent : NSObject

The MoPub iOS SDK mediates third-party native ad networks using custom events. Custom events are responsible for instantiating and manipulating native ad objects in the third-party SDK and translating and communicating events from those objects back to the MoPub SDK by notifying a delegate.

MPNativeCustomEvent is a base class for custom events that support native ads. By implementing subclasses of MPNativeCustomEvent you can enable the MoPub SDK to support a variety of third-party ad networks.

Your implementation should create an MPNativeAd object using an appropriate MPNativeAdAdapter for your network. Your custom event should also call the appropriate MPNativeCustomEventDelegate methods.

At runtime, the MoPub SDK will find and instantiate an MPNativeCustomEvent subclass as needed and invoke its -requestAdWithCustomEventInfo: method.

Public Properties

Communicating with the MoPub SDK

/delegate

  • Description: The MPNativeCustomEventDelegate receives messages concerning the status of loading a native ad. The delegate object defines several methods that you should call in order to inform MoPub of the progress of your custom event.

  • Declaration:

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

/localExtras

  • Description: An optional dictionary containing extra local data.

  • Declaration:

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

Public Methods

Requesting a Native Ad

-/requestAdWithCustomEventInfo:

  • Description: Called when the MoPub SDK requires a new native ad. When the MoPub SDK receives a response indicating it should load a custom event, it will send this message to your custom event class. Your implementation should load a native ad from a third-party ad network.

  • Declaration:

    - (void)requestAdWithCustomEventInfo:(NSDictionary *)info;
    
  • Parameters:

    • info: A dictionary containing additional custom data associated with a given custom event request. This data is configurable on the MoPub website, and may be used to pass dynamic information, such as publisher IDs.

Caching Image Resources

-/precacheImagesWithURLs:completionBlock:

  • Description: Downloads and pre-caches images. If your ad network does not provide built-in support for image caching, you may invoke this method in your custom event implementation to pre-cache image assets. If you do call this method, you should wait until the completion block is called before invoking the appropriate success or failure callbacks on the MPNativeCustomEventDelegate.

  • Declaration:

    - (void)precacheImagesWithURLs:(NSArray *)imageURLs
                 completionBlock:(void (^)(NSArray *))completionBlock;
    
  • Parameters:

    • imageURLs: An array of NSURL objects representing image resource locations.

    • completionBlock: A block that will be called after all download operations are complete. If any image downloads do not complete successfully, the errors parameter will contain error information about the failures.

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.)