This document outlines the steps to integrate the Primis Video Player into your iOS mobile application using AppLovin MAX as the primary mediation layer. By following this guide, you will be able to serve the Primis player within a standard 300x250 MREC placement and utilize Primis video demand for your apps.
Prerequisites
Before beginning the integration, ensure you have the following:
- You have received ApplovinMax SDK Integration Guide and ad units details from your Freestar Team.
- You have Google Ad Manager and ApplovinMax GAM adapters installed using cocoapods.
- The AppLovin MAX SDK has been successfully integrated into your Android or iOS project.
Implementation (Code Level)
The Primis player will be treated as a standard MREC view. Below are the implementation snippets for basic initialization and loading Primis player in an ad view.
To load an MREC ad, first create a UIViewRepresentable object, a wrapper that lets you integrate MAAdView, a UIKit view type object, into your SwiftUI view hierarchy. Also provide a custom Coordinator class for the wrapper object that conforms to MAAdViewAdDelegate. This notifies you when your ad is ready, and notifies you of other ad-related events. Inside the wrapper’s makeUIView method, create a MAAdView object that corresponds to your ad unit and call its loadAd method. To show that ad, add the UIViewRepresentable wrapper object inside your SwiftUI view hierarchy.
import AppLovinSDK
struct ExampleSwiftUIWrapper: UIViewRepresentable
{
func makeUIView(context: Context) -> MAAdView
{
let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adFormat: MAAdFormat.mrec)
adView.delegate = context.coordinator
// Set background color for banners to be fully functional
adView.backgroundColor = «background-color»
// Load the first Ad
adView.loadAd()
return adView
}
func updateUIView(_ uiView: MAAdView, context: Context) {}
func makeCoordinator() -> Coordinator
{
Coordinator()
}
}
extension ExampleSwiftUIWrapper
{
class Coordinator: NSObject, MAAdViewAdDelegate
{
// MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) {}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {}
func didClick(_ ad: MAAd) {}
func didFail(toDisplay ad: MAAd, withError error: MAError) {}
// MARK: MAAdViewAdDelegate Protocol
func didExpand(_ ad: MAAd) {}
func didCollapse(_ ad: MAAd) {}
// MARK: Deprecated Callbacks
func didDisplay(_ ad: MAAd) { /* use this for impression tracking */ }
func didHide(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}
}
// SwiftUI view to show ad
struct ExampleSwiftUIMRECAdView: View
{
// MREC width and height are 300 and 250 respectively, on iPhone and iPad
let height = 250
let width = 300
var body: some View {
ExampleSwiftUIWrapper()
.frame(width: width, height: height)
}
}Destroying MREC Ads
If you no longer need a MAAdView instance, You should destroy Ad view.
adView.removeFromSuperview()
adView.delegate = nil
adView = nilStopping auto-refresh
The MREC ad unit being set up for Primis should not refresh automatically.
adView.setExtraParameterForKey("allow_pause_auto_refresh_immediately", value: "true")
adView.stopAutoRefresh()Manually refresh the contents with the following call. You must stop auto-refresh before you call loadAd().
adView.loadAd()
Please reach out to your Freestar Team to test the Primis ad unit with test ads once you have completed the integration.