0
votes

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?

1
I am not exactly sure but it may has something to do with the test environment. Try it with real ads and device and see if you have this problem.Dave
First I tried test ads, they had this behaviour. Then I put live admob unit IDs. I had same results. In video I was using live Ads.GNChishti
But in your video you still get the test ad "This an interstitial test ad". Maybe the line: AddTestDevice().Dave
I will remove my test device then will share resultsGNChishti
I removed my test device and I tried with live ads and even I saw that... it again disappeared like test ads.GNChishti

1 Answers

0
votes

Here is the life saver answer. I also had the same problem and found the answer in a google groups. If you use the same reference to create a new one (most probably immediately after showing the ads), you are losing the current interstitial ad and it disappears. It seems that google had changed something at their backends because I have been doing the same thing for more than 3 years and no disappear was occuring. But with the recent sdk's, if you use the same interstitial object to create a new one, you lose it. Just create a new one when you need, don't use the former reference to it.