Import CENativeAd.h, CEMediaView.h and adopt CENativeAdRequestDelegate protocol in view controller's extension. Create properties for both CENativeAd and CEMediaView.
Implement CENativeAdRequestDelegate to handle ad loaded event.
#pragma mark - CENativeAdRequestDelegate
- (void)nativeAdDidLoad:(CENativeAd *)nativeAd
{
self.mediaView = [[CEMediaView alloc] init];
// Executed when ad is ready.
[self.mediaView setNativeAd:nativeAd]; // Add mediaView into view hierarchy.
}
Add CENativeAdEventDelegate to get the ad event callback.
If you want to trace the click, impression, progress event, please implement CENativeAdEventDelegate to handle it.
#pragma mark - CENativeADEventDelegate
@protocol CENativeAdEventDelegate <NSObject>
@optional
/*!
* @brief callback while native ad is about to log impression
*
* @param nativeAd CENativeAd instance
*/
- (void) nativeAdWillTrackImpression:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while this native ad is clicked by user
*
* @param nativeAd CENativeAd instance that own this native ad component
*/
- (void) nativeAdDidClick:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while native ad finished handle click event
*
* @param nativeAd CENativeAd instance that own this native ad component
*/
- (void) nativeAdDidFinishHandlingClick:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while this native ad is video format and muted.
*
* @param nativeAd CENativeAd instance that own this native ad component
*/
- (void) nativeAdDidMute:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while this native ad is video format and unmuted.
*
* @param nativeAd CENativeAd instance that own this native ad component
*/
- (void) nativeAdDidUnmute:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while this native ad is video format and start playback.
*
* @param nativeAd CENativeAd instance that own this native ad component
*/
- (void) nativeAdDidVideoStart:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while this native ad is video format and playback to end.
*
* @param nativeAd CENativeAd instance that own this native ad component
*/
- (void) nativeAdDidVideoEnd:(nonnull CENativeAd *)nativeAd;
/*!
* @brief callback while this native ad is video format and progress state.
*
* @param nativeAd CENativeAd instance that own this native ad component
* @param totalDuration this video total duration time (ms)
* @param currentPosition this video current play back position time (ms)
*/
- (void) nativeAdDidVideoProgress:(nonnull CENativeAd *)nativeAd
duration:(int)totalDuration
position:(int)currentPosition;
/*!
* @brief callback while this native ad is failed to render.
*
* @param nativeAd CENativeAd instance that own this native ad component
* @param error NSError error for rendering
*/
- (void) nativeAdOnFailedToRender:(nonnull CENativeAd *)nativeAd error:(nonnull NSError *)error;
@end