Table of Contents
Purpose
This document describes how to use YouAppi SDK on Unity with YouAppi MoPub adapter.
Setup Unity
Add MoPub mediation Unity package to your project (you can refer MoPub web site for full integration instructions).
Android
- Download YouAppi Android SDK from: youappi-sdk-android
- In Unity project under the folder: Assets/Android add the following assets:
- YouAppi’s SDK: youappi-sdk-android-moat.aar
- Google Gson support: gson-2.8.0.jar (needed by YouAppi’s SDK).
- YouAppi’s MoPub adapter: youappi-sdk-android-mopub.aar
iOS
- Download YouAppi Android SDK from: youappi-sdk-ios
- In Unity project under the folder: Assets/iOS add the following assets:
- YouAppi’s SDK: YouAppiMoat.framework
- YouAppi’s MoPub adapter: libMopubYouAppiAdapter.a
Setup MoPub
- Setup MoPub console with proper CUSTOM EVENT CLASS:
- For Android:
- Rewarded Video: com.youappi.sdk.mediation.mopub.YouAppiRewardedVideo
- Interstitial Video: com.youappi.sdk.mediation.mopub.YouAppiInterstitialVideo
- Interstitial Ad: com.youappi.sdk.mediation.mopub.YouAppiInterstitialAd
- For iOS:
- Rewarded Video: YAMoPubRewardedVideoAdEvent
- Interstitial Video: YAMoPubInterstitialVideoAdEvent
- Interstitial Ad: YAMoPubInterstitialAdEvent
- For Android:
- Setup MoPub console with proper CUSTOM EVENT DATA. For example:
{
"accessToken": "821cfa77-3127-42b5-9e6b-0afcecf77c69",
"adUnitId": "testRewardedVideoAdUnitId"
}
Here is how it looks on MoPub console:
Show Rewarded Video
Using MoPub mediation SDK create a rewarded video unit and use it to load a rewarded video and show it.
For example:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using MoPubReward = MoPubManager.MoPubReward;
public class Test : MonoBehaviour {
public static readonly string AdUnitId = "<Your MoPub ad unit id>";
public static readonly string[] AdUnitIds = { AdUnitId };
List<MoPubMediationSetting> mediationSettings = new List<MoPubMediationSetting>();
// Use this for initialization
void Start () {
Debug.Log("Initializing MoPub rewarded video");
MoPub.loadRewardedVideoPluginsForAdUnits(AdUnitIds);
MoPub.initializeRewardedVideo();
}
void OnEnable() {
Debug.Log("Attaching rewarded video events");
MoPubManager.onRewardedVideoLoadedEvent += onRewardedVideoLoadedEvent;
MoPubManager.onRewardedVideoFailedEvent += onRewardedVideoFailedEvent;
}
void OnDisable() {
Debug.Log("Detaching rewarded video events");
MoPubManager.onRewardedVideoLoadedEvent -= onRewardedVideoLoadedEvent;
MoPubManager.onRewardedVideoFailedEvent -= onRewardedVideoFailedEvent;
}
public void loadRewardedVideo() {
Debug.Log("Loading rewarded video");
MoPub.requestRewardedVideo(AdUnitId);
}
void onRewardedVideoLoadedEvent(string adUnitId)
{
Debug.Log("onRewardedVideoLoadedEvent: " + adUnitId);
MoPub.showRewardedVideo(AdUnitId);
}
void onRewardedVideoFailedEvent(string errorMsg)
{
Debug.Log("onRewardedVideoFailedEvent: " + errorMsg);
status_text.text = "Rewarded video failed loading: " + errorMsg;
}
}
Export project
Android
Simply export to Android.
iOS
After exporting to iOS project the following should be verified and setup:
- In General Tab make sure Deployment Target is at least 8.0.
- In General Tab add to Embedded Binaries: YouAppiMoat.framework.
- In Build Settings set Always Embed Swift Standard Libraries to Yes.