Unity admob插页广告显示后突然消失

时间:2019-05-01 02:04:51

标签: c# unity3d admob interstitial

我的iOS游戏有以下代码,我只是将其集成到一个空的场景中

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");
         }
     }
 }

当我的广告显示1秒钟,然后自动消失。这是解释我的问题的视频链接

https://www.dropbox.com/s/kvrjew0cr8ayqzo/LDFA2437.MP4?dl=0

我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

这是救生员的答案。我也有同样的问题,并在Google网上论坛中找到了答案。如果您使用相同的引用来创建新的引用(很可能是在展示广告之后立即创建),则您将丢失当前的插页式广告,该广告将消失。谷歌似乎已经改变了他们后端的某些东西,因为我从事同一件事已经超过三年了,并且没有消失。但是对于最近的SDK,如果您使用相同的插页式对象创建一个新的插页对象,则会丢失它。只需在需要时创建一个新的,不要使用以前的引用。