iOS - Mediation Network Setup
Guide to integrating TargetVideoMediation Adapter into your iOS app.
Dependency Setup via Cocopods
Import the AppLovinSDK and TargetVideoMediationAdapterIOS via Cocopods (SPM still not supported by AppLovin).
pod 'AppLovinSDK'
pod 'TargetVideoMediationAdapterIOS'
Initialize AppLovinSDK in the AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let initConfig = ALSdkInitializationConfiguration(sdkKey: Constants.AppLovinSdkKey) { builder in
builder.mediationProvider = ALMediationProviderMAX
}
// Initialize the SDK with the configuration
ALSdk.shared().initialize(with: initConfig) { sdkConfig in
// Start loading ads
}
return true
}
Load and Show a Rewarded Ad
TargetVideo’s rewarded ads use Google IMA and AVPlayer to deliver high-quality fullscreen video playback. Conform to AppLovin's MARewardedAdDelegate to recieve adapters actions.
An Example in a UIViewController class
import TargetVideoMediationAdapterIOS
import AppLovinSDK
class ViewController: UIViewController {
// MARK: - Properties
private var rewardedAd: MARewardedAd!
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
createRewardedAd()
}
private func createRewardedAd() {
rewardedAd = MARewardedAd.shared(withAdUnitIdentifier: Constants.AppLovinRewardedAdUnit)
rewardedAd.delegate = self
// Load the first ad
rewardedAd.load()
}
}
// MARK: - MARewardedAdDelegate
extension SearchViewController: MARewardedAdDelegate {
func didRewardUser(for ad: MAAd, with reward: MAReward) {
showOkAlert(title: "Reward earned", message: "You have earned a reward")
}
func didLoad(_ ad: MAAd) {
if rewardedAd.isReady {
rewardedAd.show()
}
}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {
rewardedAd.load()
}
func didDisplay(_ ad: MAAd) {
}
func didHide(_ ad: MAAd) {
}
func didClick(_ ad: MAAd) {
}
func didFail(toDisplay ad: MAAd, withError error: MAError) {
rewardedAd.load()
}
}
b) Show the TargetVideo Rewarded ad
if rewardedAd.isReady {
rewardedAd.show()
}
Updated about 1 month ago