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 aaac89b commit 313bb13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ - (void)didCloseAd {
}

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

Expand Down
65 changes: 24 additions & 41 deletions adapters/Vungle/VungleAdapter/GADMAdapterVungleRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#import "GADMAdapterVungleRouter.h"
#import "GADMAdapterVungleBannerRequest.h"
#import "GADMAdapterVungleConstants.h"
#import "GADMAdapterVungleUtils.h"
#import "VungleRouterConsent.h"
Expand Down Expand Up @@ -197,8 +196,7 @@ - (void)replaceOldBannerDelegateWithDelegate:(nonnull id<GADMAdapterVungleDelega
}

- (nullable id<GADMAdapterVungleDelegate>)getDelegateForPlacement:(nonnull NSString *)placement
withBannerRouterDelegateState:
(BannerRouterDelegateState)bannerState {
withBannerRouterDelegateState:(BannerRouterDelegateState)bannerState {
id<GADMAdapterVungleDelegate> delegate = nil;
@synchronized(_bannerDelegates) {
if ([_bannerDelegates objectForKey:placement]) {
Expand Down Expand Up @@ -266,49 +264,32 @@ - (nullable NSError *)loadAd:(nonnull NSString *)placement
withDelegate:(nonnull id<GADMAdapterVungleDelegate>)delegate {
if (!delegate) {
return GADMAdapterVungleErrorWithCodeAndDescription(
kGADErrorMediationAdapterError, @"Can't load ad when try to add a nil delegate.");
kGADErrorMediationAdapterError, @"Can't load ad when try to add a nil delegate.");
}

id<GADMAdapterVungleDelegate> adapterDelegate = [self getDelegateForPlacement:placement];
if (adapterDelegate) {
NSError *error = GADMAdapterVungleErrorWithCodeAndDescription(
return GADMAdapterVungleErrorWithCodeAndDescription(
kGADErrorMediationAdapterError, @"Can't request ad if another request is processing.");
return error;
}

BOOL addSuccessed = [self addDelegate:delegate];
if (!addSuccessed) {
return GADMAdapterVungleErrorWithCodeAndDescription(
kGADErrorMediationAdapterError, @"A banner ad type has already been "
@"instantiated. Multiple banner ads are not "
@"supported with Vungle iOS SDK.");
kGADErrorMediationAdapterError, [NSString stringWithFormat:
@"Ad already loaded for placement ID: %@",placement]);
}

VungleSDK *sdk = [VungleSDK sharedSDK];
if ([self isAdCachedForPlacementID:placement withDelegate:delegate]) {
[delegate adAvailable];
} else {
// We already requested an ad for _prioritizedPlacementID,
// so we don't need to request again.
if ([_prioritizedPlacementID isEqualToString:placement]) {
return nil;
}
return nil;
}

NSError *loadError = nil;
GADMAdapterVungleAdType adType = [delegate adapterAdType];
if (adType != GADMAdapterVungleAdTypeBanner && adType != GADMAdapterVungleAdTypeShortBanner && adType != GADMAdapterVungleAdTypeLeaderboardBanner) {
if (![sdk loadPlacementWithID:placement error:&loadError]) {
if (loadError) {
return loadError;
}
}
} else {
if (![sdk loadPlacementWithID:placement withSize:[self getVungleBannerAdSizeType:adType] error:&loadError]) {
if ((loadError) && (loadError.code != VungleSDKResetPlacementForDifferentAdSize)) {
return loadError;
}
}
}
// We already requested an ad for _prioritizedPlacementID,
// so we don't need to request again.
if ([_prioritizedPlacementID isEqualToString:placement]) {
return nil;
}

NSError *loadError = nil;
Expand Down Expand Up @@ -478,8 +459,7 @@ - (void)vungleWillShowAdForPlacementID:(nullable NSString *)placementID {

id<GADMAdapterVungleDelegate> delegate =
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStateWillPlay];

withBannerRouterDelegateState:BannerRouterDelegateStateWillPlay];
[delegate willShowAd];
}

Expand All @@ -489,15 +469,15 @@ - (void)vungleDidShowAdForPlacementID:(nullable NSString *)placementID {

- (void)vungleWillCloseAdForPlacementID:(nonnull NSString *)placementID {
id<GADMAdapterVungleDelegate> delegate =
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStatePlaying];
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStatePlaying];
[delegate willCloseAd];
}

- (void)vungleDidCloseAdForPlacementID:(nonnull NSString *)placementID {
id<GADMAdapterVungleDelegate> delegate =
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStateClosing];
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStateClosing];

if (!delegate) {
return;
Expand All @@ -508,21 +488,24 @@ - (void)vungleDidCloseAdForPlacementID:(nonnull NSString *)placementID {
}

- (void)vungleTrackClickForPlacementID:(nullable NSString *)placementID {
id<GADMAdapterVungleDelegate> delegate = [self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStatePlaying];
id<GADMAdapterVungleDelegate> delegate =
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStatePlaying];
[delegate trackClick];
}

- (void)vungleRewardUserForPlacementID:(nullable NSString *)placementID {
id<GADMAdapterVungleDelegate> delegate = [self getDelegateForPlacement:placementID];
if (delegate.adapterAdType == GADMAdapterVungleAdTypeRewarded && [delegate respondsToSelector:@selector(rewardUser)]) {
if (delegate.adapterAdType == GADMAdapterVungleAdTypeRewarded &&
[delegate respondsToSelector:@selector(rewardUser)]) {
[delegate rewardUser];
}
}

- (void)vungleWillLeaveApplicationForPlacementID:(nullable NSString *)placementID {
id<GADMAdapterVungleDelegate> delegate = [self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStatePlaying];
id<GADMAdapterVungleDelegate> delegate =
[self getDelegateForPlacement:placementID
withBannerRouterDelegateState:BannerRouterDelegateStatePlaying];
if ([delegate respondsToSelector:@selector(willLeaveApplication)]) {
[delegate willLeaveApplication];
}
Expand Down

0 comments on commit 313bb13

Please sign in to comment.