π₯οΈNative Ad
extension NativeAdManager: MediationAdDelegate {
func onNativeAdLoaded(nativeAd: AdsFramework.MediationNativeAd) {
nativeAd.eventDelegate = self
guard let nibObjects = Bundle.main.loadNibNamed("NativeView", owner: nil, options: nil),
let adView = nibObjects.first as? MediationNativeAdView else {
printLog("Could not load nib file for adView")
return
}
(adView.bodyView as? UILabel)?.text = nativeAd.body
(adView.headlineView as? UILabel)?.text = nativeAd.headline
(adView.ctaView as? UIButton)?.setTitle(nativeAd.callToAction, for: .normal)
(adView.ctaView as? UIButton)?.isUserInteractionEnabled = false
if let mediaView = nativeAd.mediaView {
addMediaViewToParentView(childView: mediaView, parentView: adView.mediaView)
}
adView.setNativeAd(nativeAd: nativeAd)
viewBanner.addSubview(adView)
}
func onAdFailedToLoad(error: AdError) {
print("Native Ad request failed with reason \(error.description)")
}
}Last updated