Skip to content

Commit

Permalink
Add latest changes from AdMob
Browse files Browse the repository at this point in the history
  • Loading branch information
YueVungle committed Jun 10, 2020
1 parent cd2858c commit 019a448
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 89 deletions.
20 changes: 13 additions & 7 deletions adapters/Vungle/VungleAdapter/GADMAdapterVungleInterstitial.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ @implementation GADMAdapterVungleInterstitial {
/// Indicates whether the banner ad finished presenting or not.
BOOL _didBannerFinishPresenting;

/// Indicates whether the interstitial ad is presenting or not.
BOOL _isInterstitialAdPresenting;
/// Indicates whether a banner or interstitial ad is loaded.
BOOL _isAdLoaded;

/// The CGSize of Banner Ad view
CGSize _bannerSize;
Expand Down Expand Up @@ -187,7 +187,6 @@ - (void)presentInterstitialFromRootViewController:(UIViewController *)rootViewCo
[strongConnector adapterDidDismissInterstitial:self];
return;
}
_isInterstitialAdPresenting = YES;
}

#pragma mark - Private methods
Expand Down Expand Up @@ -244,10 +243,14 @@ - (void)initialized:(BOOL)isSuccess error:(nullable NSError *)error {
}

- (void)adAvailable {
if (_isAdLoaded) {
// Already invoked an ad load callback.
return;
}
_isAdLoaded = YES;

if (self.adapterAdType == GADMAdapterVungleAdTypeInterstitial) {
if (!_isInterstitialAdPresenting) {
[_connector adapterDidReceiveInterstitial:self];
}
[_connector adapterDidReceiveInterstitial:self];
}

if ([self isBannerAd]) {
Expand All @@ -257,6 +260,10 @@ - (void)adAvailable {
}

- (void)adNotAvailable:(nonnull NSError *)error {
if (_isAdLoaded) {
// Already invoked an ad load callback.
return;
}
[_connector adapter:self didFailAd:error];
}

Expand All @@ -278,7 +285,6 @@ - (void)willCloseAd {

if (self.adapterAdType == GADMAdapterVungleAdTypeInterstitial) {
[strongConnector adapterWillDismissInterstitial:self];
_isInterstitialAdPresenting = NO;
}
}

Expand Down
34 changes: 20 additions & 14 deletions adapters/Vungle/VungleAdapter/GADMAdapterVungleRewardedAd.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ @implementation GADMAdapterVungleRewardedAd {
GADMediationRewardedLoadCompletionHandler _adLoadCompletionHandler;

/// The ad event delegate to forward ad rendering events to the Google Mobile Ads SDK.
__weak id<GADMediationRewardedAdEventDelegate> _delegate;
id<GADMediationRewardedAdEventDelegate> _delegate;

/// Indicates whether the rewarded ad is presenting.
BOOL _isRewardedAdPresenting;
/// Indicates whether the rewarded ad is loaded.
BOOL _isAdLoaded;
}

- (nonnull instancetype)
Expand Down Expand Up @@ -112,7 +112,6 @@ - (void)loadRewardedAd {
}

- (void)presentFromViewController:(nonnull UIViewController *)viewController {
_isRewardedAdPresenting = YES;
if (![[GADMAdapterVungleRouter sharedInstance] playAd:viewController
delegate:self
extras:[_adConfiguration extras]]) {
Expand Down Expand Up @@ -141,15 +140,19 @@ - (void)initialized:(BOOL)isSuccess error:(nullable NSError *)error {
}

- (void)adAvailable {
if (!_isRewardedAdPresenting) {
if (_adLoadCompletionHandler) {
_delegate = _adLoadCompletionHandler(self, nil);
}

if (!_delegate) {
// In this case, the request for Vungle has been timed out. Clean up self.
[[GADMAdapterVungleRouter sharedInstance] removeDelegate:self];
}
if (_isAdLoaded) {
// Already invoked an ad load callback.
return;
}
_isAdLoaded = YES;

if (_adLoadCompletionHandler) {
_delegate = _adLoadCompletionHandler(self, nil);
}

if (!_delegate) {
// In this case, the request for Vungle has been timed out. Clean up self.
[[GADMAdapterVungleRouter sharedInstance] removeDelegate:self];
}
}

Expand All @@ -162,7 +165,6 @@ - (void)didCloseAd {
}

- (void)willCloseAd {
_isRewardedAdPresenting = NO;
[_delegate willDismissFullScreenView];
}

Expand All @@ -174,6 +176,10 @@ - (void)willShowAd {
}

- (void)adNotAvailable:(nonnull NSError *)error {
if (_isAdLoaded) {
// Already invoked an ad load callback.
return;
}
_adLoadCompletionHandler(nil, error);
[[GADMAdapterVungleRouter sharedInstance] removeDelegate:self];
}
Expand Down
Loading

0 comments on commit 019a448

Please sign in to comment.