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

[GoogleMobileAdsVungleMediation-3.2.0] Interstitial ad OnAdClosed callback is never called -100% #1228

Closed ishnu47 closed 1 year ago

ishnu47 commented 4 years ago

Hello, I'm using AdMob mediation with GoogleMobileAdsVungleMediation-3.2.0, and the OnAdClosed callback of all interstitial ads (from Vungle) will never be triggered.

Here is my specs:

I tried to downgrade adapter to 3.1.4 and it works fine without any problem, but I got UIWebView deprecated warning when upload to Itunes Connects, so I can not use it.

Could you please help? Thank you.

ishnu47 commented 4 years ago

It seems that if the last Unity interstitial ad was shown, and the next interstitial ad is Vungle, then the OnAdClosed will never be triggered.

I had to fix this issue by implement my own solution, listening to UnityGLView event (appear, disappear) to detect when an interstitial ad is closed.

kpfiledots commented 4 years ago

It seems that if the last Unity interstitial ad was shown, and the next interstitial ad is Vungle, then the OnAdClosed will never be triggered.

I had to fix this issue by implement my own solution, listening to UnityGLView event (appear, disappear) to detect when an interstitial ad is closed.

@ishnu47 Hello! I believe I am running into the same issue as you, but instead with the Facebook Audience Network mediation adapter. Would you be able to share the code for your solution? I'm not quite sure how to do what you are describing.

ishnu47 commented 4 years ago

@kpfiledots Here is the code:

#import <Foundation/Foundation.h>
#define DEFINE_NOTIFICATION(name) extern "C" __attribute__((visibility ("default"))) NSString* const name;

DEFINE_NOTIFICATION(kUnityViewDidAppear);

@interface InterstitialAdClosedObserver : NSObject
@property (nonatomic, readonly) BOOL isPlayingAd;
+ (instancetype)sharedManager;
- (void)startPlayingAd;
@end

@implementation InterstitialAdClosedObserver
#pragma mark Singelton

+ (instancetype)sharedManager {
    static InterstitialAdClosedObserver *sharedManager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager = [[InterstitialAdClosedObserver alloc] init];
    });
    return sharedManager;
}

#pragma mark Initialization

- (id)init {
    self = [super init];
    if (self) {
        _isPlayingAd = YES;

        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(unityViewDidAppear:) name: kUnityViewDidAppear object: nil];
    }
    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kUnityViewDidAppear object:nil];
}

- (void)unityViewDidAppear:(NSNotification*)notification {
    _isPlayingAd = NO;
}

- (void)startPlayingAd {
    _isPlayingAd = YES;
}
@end

// Expose these functions to Unity plugin
extern "C" {
    // Call this when your game starts
    void _initAdClosedObserver() {
        [InterstitialAdClosedObserver sharedManager];
    }

    // When you start playing an interstitial ad, let start a coroutine and polling this, when you get the false value, the interstitial ad is closed.
    bool _isPlayingAd() {
        return [[InterstitialAdClosedObserver sharedManager] isPlayingAd];
    }

    // Call this when you start playing an interstitial ad (in Unity code)
    void _startPlayingAd() {
        [[InterstitialAdClosedObserver sharedManager] startPlayingAd];
    }
}

Hope this can help.

kpfiledots commented 4 years ago

@ishnu47 Thanks! It does help. I was able to create a workaround of this issue with this as well. Though, it seems there may still be some things in a bad state within the Admob or Facebook Audience Network SDK that affects some future ad loads when this issue occurs for us.

For my particular issue, we are using RewardedAd and I've tracked down that things work ok with iOS FAN SDK version 5.5.1 and stop working correctly with 5.6.0. Interestingly, this is also the upgrade that removes UIWebView usage for Facebook, which sounds similar to your problem.

More info: This problem only occurs if we try to load and cache more than one ad at a time. If we stick to one ad, it's ok, if we do two, it doesn't take long before one of the ad shows does not call either the Rewarded or Closed callbacks, and also doesn't unpause Unity, if MobileAds.SetiOSAppPauseOnBackground(true); is set.

joshuajplagonera commented 4 years ago

Hi there, Thank you for your patience.

We are currently investigating on this issue. However, I noticed that you are using an outdated version of the adapters. There has been significant changes to the iOS adapters for both Unity and Vungle. Would you be able to try and use the latest Unity Mediation plugins for Vungle and Unity and see if you can still replicate the issue ?

ishnu47 commented 4 years ago

With the new update of Google AdMob Unity SDK 5.1.0 and GoogleMobileAdsVungleMediation-3.3.0, the Vungle interstitial ad sometimes freezes my game completely. No AdClosed call back, UnityView events are not fired anymore (no viewWillAppear, viewDidAppear after the Vungle interstitial ad is closed)! Any workaround please?

stowy commented 4 years ago

this seems like it could be an issue with the Vungle SDK, but it would be hard to tell without reproducing.

Can you please post on our support forum and our support team will help debug this with you?

ishnu47 commented 4 years ago

Updated: After the Vungle interstitial ad closed, I can receive view event callbacks (viewWillAppear, viewDidAppear), but the Unity thread is still paused. So here is the reason: