Skip to main content

Native Ad Units

Create Native Ad Unit#

info

If you miss to Initialize the SDK, this method will fail to return a response.

To create an native ad, first create an MesonNative object

var nativeAd: MesonNative = MesonNative.init(adUnitId: "AD_UNIT_ID", adSize: CGSize, delegate: self)

Set the Delegate#

Track the ad lifecycle for native ads. All the available events for native ads are listed below.

extension <class> : MesonNativeDelegate {
func mesonNativeDidLoad(_ nativeAd: MesonNative) {
}
func mesonNativeDidLoadFail(_ nativeAd: MesonNative, error: Error) {
}
func mesonNativeDidClick(_ nativeAd: MesonNative, params: [String : Any]?) {
}
func mesonNativeImpression(_ nativeAd: MesonNative, impressionData: [String: Any]) {
}
func mesonNativeWillPresentScreen(_ nativeAd: MesonNative) {
}
func mesonNativeDidPresentScreen(_ nativeAd: MesonNative) {
}
func mesonNativeWillCollapseScreen(_ nativeAd: MesonNative) {
}
func mesonNativeDidCollapseScreen(_ nativeAd: MesonNative) {
}
func mesonNativeUserWillLeaveApplication(_ nativeAd: MesonNative) {
}
}

Load Ad#

The publisher can request for a native in-feed ad by invoking this method. This will request an ad from all demand sources, select a winner, and make it available on the SDK.

nativeAd.load()

Get Ad View#

The ad is returned to the user when getAdView method is called. It is recommended to call this method in the mesonNativeDidLoad callback.

let adConfig = MesonNativeAdViewConfiguration(size: <CGSize>, window: <UIWindow>, topViewController: <UIViewController>)
nativeAd.getAdView(configuration: adConfig)