I have following code for my iOS game I am just integrating it in an empty scene
public class AdController : MonoBehaviour
{
void Start()
{
print ("------------------ initializing ads --------------------");
#if UNITY_ANDROID
string appId = "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string appId = "ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxxxxxxxxxx";
#else
string appId = "unexpected_platform";
#endif
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize (appId);
RequestInterstitial();
}
private InterstitialAd interstitial;
private void RequestInterstitial()
{
print ("----------- RequestInterstitial -------------");
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxx";
#else
string adUnitId = "unexpected_platform";
#endif
this.interstitial = new InterstitialAd(adUnitId);
// Called when an ad request has successfully loaded.
this.interstitial.OnAdLoaded += HandleOnAdLoaded;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().
AddTestDevice("xxxxxxxxxxmydevicexxxxxxxxxxx")
.Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
print("HandleAdLoaded event received");
showInterstitial ();
}
void showInterstitial()
{
if (this.interstitial.IsLoaded ()) {
this.interstitial.Show ();
} else {
print ("ad not ready yet");
}
}
}
when my ad shows for 1 second and then it disappears automatically. Here is video link for explaining my problem
https://www.dropbox.com/s/kvrjew0cr8ayqzo/LDFA2437.MP4?dl=0
Anything I am doing wrong?
AddTestDevice()
. – Dave