In this article, you will learn how to use Nimbus to request and render Liftoff Ads.
Integrating Nimbus with Liftoff Monetize requires an App ID.
How it works
The SDK will automatically inject the Vungle token and app id into the outbound request to Nimbus when using the NimbusAdManager. When the NimbusVungleRequestInterceptor is initialized it will fetch the Liftoff Monetize token in the background for use on future requests and install the NimbusVungleAdRenderer to render any wins from Liftoff Monetize.
Installation
Swift Package Manager
Following the steps defined in the integration section to install Nimbus using Swift Package Manager, include the package 'NimbusVungleKit' in the selected packages.
CocoaPods
Add NimbusVungleKit subspec for the NimbusSDK declaration into your project’s Podfile. pod 'NimbusSDK', subspecs: ['NimbusKit', 'NimbusVungleKit']
Run pod install
The Liftoff Monetize SDK will be automatically installed when using CocoaPods or Swift Package Manager
Configure the SDK to include Liftoff Monetize
Be sure Nimbus is initialized before continuing with the Liftoff integration.
Include the Liftoff Monetize interceptor and renderer.
To be notified when Liftoff Monetize finishes its initialization, your class must implement NimbusVungleRequestInterceptorDelegate. This can be used to monitor any errors.
A native ad view is a UIView that is responsible for the visual representation of a native Liftoff Monetize ad. Nimbus requires such view to conform to NimbusVungleNativeAdViewType protocol in order to pass Liftoff Monetize SDK everything it needs.
The protocol is defined as:
publicprotocolNimbusVungleNativeAdViewType:UIView {// Vungle media view, it must be an instance of VungleAdsSDK.MediaViewvar mediaView: MediaView { getset }// An icon viewvar iconImageView: UIImageView? { getset }// Array of views that trigger the ad click action, e.g. [ mediaView ]// would make only the mediaView clickablevar clickableViews: [UIView]? { get }}
If you want to get quickly started, feel free to use the native ad view snippet below, that already conforms to NimbusVungleNativeAdViewType protocol, or check out the public sample app where we showcase a native Liftoff ad.
NimbusVungleAdRenderer has a new property named adRendererDelegate. It's required to implement the delegate to use native Liftoff ads.
The ad renderer delegate has only one method: customViewForRendering(...) which asks you to provide a native ad view that should be used for rendering.
Important: Do not at any point add the native ad view to the view hierarchy, our SDK does that later.
Complete Example
Let's take a look at the following code snippet of a UIViewController that can display a native ad.
importUIKitimportNimbusVungleKitimportVungleAdsSDKfinalclassVungleNativeAdViewController:UIViewController {privatevar adManager =NimbusAdManager()privatevar adController: AdController?privatelet nativeAdContentView =UIView()overridefuncviewDidLoad() { super.viewDidLoad() view.backgroundColor = .white// Make sure Liftoff interceptor is setlet renderer =NimbusVungleAdRenderer()// Notice we set the adRendererDelegate renderer.adRendererDelegate = self Nimbus.shared.renderers[.forNetwork("vungle")]= renderersetupContentView() adManager.delegate = self adManager.showAd( request: NimbusRequest.forNativeAd(position:"position"), container: nativeAdContentView, adPresentingViewController: self) }// We set the Auto Layout constraints of our container viewfuncsetupContentView() { nativeAdContentView.translatesAutoresizingMaskIntoConstraints =false view.addSubview(nativeAdContentView) NSLayoutConstraint.activate([ nativeAdContentView.centerYAnchor.constraint(equalTo: view.centerYAnchor), nativeAdContentView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), nativeAdContentView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor), nativeAdContentView.widthAnchor.constraint(equalToConstant:300), nativeAdContentView.heightAnchor.constraint(equalToConstant:300) ]) }}extensionVungleNativeAdViewController:NimbusAdManagerDelegate {funcdidRenderAd(request: NimbusRequest, ad: NimbusAd, controller: AdController) {print("didRenderAd") adController = controller }funcdidCompleteNimbusRequest(request: NimbusRequest, ad: NimbusAd) {print("didCompleteNimbusRequest") }funcdidFailNimbusRequest(request: NimbusRequest, error: NimbusError) {print("didFailNimbusRequest: \(error.localizedDescription)") }}// Here we simply return the custom view we want to use to render// the native ad. We don't add it to the view hierarchy, just instantiate it// using the Liftoff native ad that the delegate provides us with.extensionVungleNativeAdViewController:NimbusVungleAdRendererDelegate {funccustomViewForRendering(container: UIView, nativeAd: VungleNative) -> NimbusVungleNativeAdViewType {NimbusVungleNativeAdView(nativeAd) }}