googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.37k stars 1.08k forks source link

Google Mobile Ads Unity Plugin v3.18.2 first Interstitial ad fails to show #991

Closed Chelovek-Pauk closed 1 year ago

Chelovek-Pauk commented 5 years ago

Hello!

For quite a while I am experiencing an issue when first time after launching the app the Interstitial ad on any placement shows one frame, then no image, but sound remains. The problem is that no OnAdClosed handler is called in this situation and there are problems on IOS when You should destroy the interstitial ad instance when ad closes to load a new one.

The sound from failed first ad remains even when a new ad shows.

Unity version: 2019.1.9f1 I ve done code according to the instruction here: https://developers.google.com/admob/unity/interstitial

here is the video example of issue: https://youtu.be/ykgI4qGCg0c

Chelovek-Pauk commented 5 years ago

platform: IOS device: iPad mini 2

Chelovek-Pauk commented 5 years ago

Hello again!

Any thoughts on the issue? Maybe more information needed?

UragayalaDeepika commented 5 years ago

@Chelovek-Pauk Can you please share the code snippets of your implementation or sample project for us to take a look? Can you also go through our sample script and see if you are missing something with your implementation?

Chelovek-Pauk commented 5 years ago

@UragayalaDeepika

[Updated] Here is my implementation code:

  private InterstitialAd interstitial;

 void Start()
{
 #if UNITY_IOS
    string appId = "ca-app-pub-5759662936419616~6470499999";
#else
        string appId = "unexpected_platform";
 #endif

MobileAds.Initialize(appId);

RequestInterstitial();
 }

 private void RequestInterstitial()
{

  #if UNITY_IOS
    string adUnitId = "ca-app-pub-5759662936419616/6640000000";
 #else
    string adUnitId = "unexpected_platform";
  #endif
    //this.interstitial.Destroy();
    // Initialize an InterstitialAd.
    this.interstitial = new InterstitialAd(adUnitId);

    // Create an empty ad request.
    AdRequest request = new   AdRequest.Builder().Build();

    // Load the interstitial with the request.
    this.interstitial.LoadAd(request);

    this.interstitial.OnAdLoaded += HandleOnIntAdLoaded;
    // Called when an ad request failed to load.
    this.interstitial.OnAdFailedToLoad += HandleOnIntAdFailedToLoad;
    // Called when an ad is shown.
    this.interstitial.OnAdOpening += HandleOnIntAdOpened;
    // Called when the ad is closed.
    this.interstitial.OnAdClosed += HandleOnIntAdClosed;
    // Called when the ad click caused the user to leave the application.
    this.interstitial.OnAdLeavingApplication += HandleOnIntAdLeavingApplication;
   }

  public void HandleOnIntAdLoaded(object sender, EventArgs args)
{
    //MonoBehaviour.print("HandleAdLoaded event received");
}

public void HandleOnIntAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    Debug.Log("HandleFailedToReceiveAd event received with message: "
                       + args.Message);
    this.interstitial.Destroy();
    //RequestInterstitial();
}

public void HandleOnIntAdOpened(object sender, EventArgs args)
{
    //MonoBehaviour.print("HandleAdOpened event received");
    MobileAds.SetApplicationVolume(1.0f);
}

public void HandleOnIntAdClosed(object sender, EventArgs args)
{
    //MonoBehaviour.print("HandleAdClosed event received");
    PlayerPrefs.SetInt("SoundOn", 1);
    this.interstitial.Destroy();
    RequestInterstitial();
}

public void HandleOnIntAdLeavingApplication(object sender, EventArgs args)
{
   // MonoBehaviour.print("HandleAdLeavingApplication event received");
}

void ShowInterstitial()
{
 if (this.interstitial.IsLoaded())
   {
          this.interstitial.Show();
   }

 }
Chelovek-Pauk commented 5 years ago

Don't see any differences with Your sample project, except maybe destroying Interstitial ad instance before creating very first Interstitial ad, but I suppose it should be null at the start:

private InterstitialAd interstitial;


Also I've noticed this line in Start() void: MobileAds.SetiOSAppPauseOnBackground(true);

Isn't this gonna freeze game on start?

UragayalaDeepika commented 5 years ago

@Chelovek-Pauk Can you confirm that the issue is only happening when you are trying to show the Interstitial for the first time? And it auto closes? I do notice the issue from your video recording. Can you also provide us with code snippets for when ShowInterstitial() is called? Also, you do not need to Destroy() the Interstitial onAdClosed() since this is taken care by the plugin.

And - MobileAds.SetiOSAppPauseOnBackground(true) Isn't this gonna freeze game on start?

This would not freeze the app and is only setting the audio property for the Ad that is requested and when shown to the user and not for your application.

Chelovek-Pauk commented 5 years ago

@UragayalaDeepika Yes, that is right, I can confirm that the issue is happening only when the first Interstitilal ad shows up since the game session started/app was launched (I guess, since the Admob plugin was initialized). The following ads shows and sounds correctly.

By the way, if this information can help, when the first interstitial ad auto closes, the sound of the ad video remains and You can hear it in the game and even when the next Interstitial ad shows up (so there are two sounds from two ads at the same time).

The code of ShowInterstitial() method call looks like this:

void Update()
{

......

if(win_condition && !ad_shown)
   {
 ShowInterstitial();
 ad_shown=true;
   }

}

Hope this information can help!

UragayalaDeepika commented 5 years ago

@Chelovek-Pauk I see that you are requesting ShowInterstitial() in Update() callback and I would recommend that you be careful when you do so. I'm not sure what the win_condition and ad_shown flags depend on and my recommendation is to ensure that this is not called in succession. Can you add a log and check whether this is happening as I'm quite certain that this is now an integration issue.

Chelovek-Pauk commented 5 years ago

@UragayalaDeepika Could You please clarify why it is bad to call ShowInterstitial() in Update()? If the problem is due to multiple calls of ShowInterstitial() in several frames in a row - I've checked, this is not happening for sure. In Integration Sample I've seen You show ad in OnGui() method - is it necessary to show ads in this particular method?

Originally, I have 2 interstitial ad placements - one of them I call at the end of the level in Update() (as I described earlier). The second one is called by button click, the implementation looks like this:

private InterstitialAd interstitial2;

void Start()
{
.......
ContinueButton.onClick.AddListener(ContinueButtonClicked);
}

void ContinueButtonClicked(){

if (this.interstitial2.IsLoaded())
{
      this.interstitial2.Show();
}

}

The interstitial2 ad request methods are the same as for previous I described earlier.

So the issue is active for both placements - depends on which one is called first since MobileAds Initialization.

DrVallo commented 5 years ago

@Chelovek-Pauk I have a very similar problem with AdMob version 4.0.0. I have an app crash when I first see a RewardVideo. Were you able to solve the error? If yes, how?

Chelovek-Pauk commented 4 years ago

@DrVallo Hello! Unfortunately, the problem still remains. What's more, the problem is the same for Unity Ads SDK - when the first time interstitial ad is requested, the app just freezes and no ui clicks work. You can see this issue on video here: https://drive.google.com/file/d/1PEykoRwnpS5aaU-N0lDEX3oStY8C-awa/view The thing is that the problem is common for my project for every sdk: ironSource, Admob and Unity Ads, which makes me think that there is something wrong with my Unity project settings or Xcode settings. Were You able to resolve the issue?

DrVallo commented 4 years ago

Hello @Chelovek-Pauk , doing different tests I was able to solve the crash problem regarding RewardVideo on iOS. I discovered that before starting the ad (only on iOS) it is necessary to stop the audio of the running game (I had the soundtrack of the game activated in beckground), and reactivate it once the ad has been closed. Managing all this with a Coroutine, it seems that the app doesn't crash anymore.

Obviously I suggest you keep the AdMob plugin up to date with the latest version.

If you want to check, here you can find my app that uses AdMob: Super Fishermind in App Store

I hope I was helpful!