diff --git a/Vungle/VungleAdapter/ALVungleMediationAdapter.m b/Vungle/VungleAdapter/ALVungleMediationAdapter.m index a13baaca97..390d0dbf22 100644 --- a/Vungle/VungleAdapter/ALVungleMediationAdapter.m +++ b/Vungle/VungleAdapter/ALVungleMediationAdapter.m @@ -28,8 +28,9 @@ - (void)didFailToDisplayAppOpenAdWithError:(MAAdapterError *)adapterError; @end @interface ALVungleMediationAdapterRouter : ALMediationAdapterRouter -@property (nonatomic, copy, nullable) void(^oldCompletionHandler)(void); -@property (nonatomic, copy, nullable) void(^completionBlock)(MAAdapterInitializationStatus, NSString *_Nullable); +@property (nonatomic, copy, nullable) void(^oldCompletionHandler)(void); +@property (nonatomic, copy, nullable) void(^completionBlock)(MAAdapterInitializationStatus, NSString * _Nullable); +@property (nonatomic, copy, nullable) void(^adViewAdLoadCompletionBlock)(NSString *); @property (nonatomic, assign, getter=hasGrantedReward) BOOL grantedReward; @property (nonatomic, strong) NSMutableDictionary *creativeIdentifiers; @@ -56,8 +57,8 @@ - (instancetype)initWithFormat:(MAAdFormat *)format builderBlock:(NS_NOESCAPE MA @interface ALVungleMediationAdapter () @property (nonatomic, strong, readonly) ALVungleMediationAdapterRouter *router; @property (nonatomic, copy) NSString *placementIdentifier; +@property (nonatomic, copy) NSString *bidResponse; @property (nonatomic, strong) UIView *adView; - // Native Ad Properties @property (nonatomic, strong) VungleNativeAd *nativeAd; @property (nonatomic, strong) ALVungleMediationAdapterNativeAdDelegate *nativeAdDelegate; @@ -138,8 +139,15 @@ - (void)destroy { if ( self.adView ) { - // Note: Not calling this for now because it clears pre-loaded/cached ad view ads as well. - // [[VungleSDK sharedSDK] finishedDisplayingAd]; + if ( self.bidResponse ) + { + [[VungleSDK sharedSDK] finishDisplayingAd: self.placementIdentifier adMarkup: self.bidResponse]; + } + else + { + [[VungleSDK sharedSDK] finishDisplayingAd: self.placementIdentifier]; + } + self.adView = nil; } @@ -184,23 +192,8 @@ - (void)loadInterstitialAdForParameters:(id)paramet delegate: delegate forPlacementIdentifier: self.placementIdentifier]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] ) - { - [self log: @"Interstitial ad loaded"]; - [delegate didLoadInterstitialAd]; - - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] ) - { - [self log: @"Interstitial ad loaded"]; - [delegate didLoadInterstitialAd]; - - return; - } + // Not allowed to skip load ad even if the ad is cached. + // That will cause nurl missing issue. NSError *error; BOOL isLoaded = [self loadAdForParameters: parameters @@ -275,23 +268,8 @@ - (void)loadAppOpenAdForParameters:(id)parameters a delegate: delegate forPlacementIdentifier: self.placementIdentifier]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] ) - { - [self log: @"App open ad loaded"]; - [delegate didLoadAppOpenAd]; - - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] ) - { - [self log: @"App open ad loaded"]; - [delegate didLoadAppOpenAd]; - - return; - } + // Not allowed to skip load ad even if the ad is cached. + // That will cause nurl missing issue. NSError *error; BOOL isLoaded = [self loadAdForParameters: parameters @@ -366,23 +344,8 @@ - (void)loadRewardedAdForParameters:(id)parameters delegate: delegate forPlacementIdentifier: self.placementIdentifier]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] ) - { - [self log: @"Rewarded ad loaded"]; - [delegate didLoadRewardedAd]; - - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] ) - { - [self log: @"Rewarded ad loaded"]; - [delegate didLoadRewardedAd]; - - return; - } + // Not allowed to skip load ad even if the ad is cached. + // That will cause nurl missing issue. NSError *error; BOOL isLoaded = [self loadAdForParameters: parameters @@ -446,6 +409,7 @@ - (void)loadAdViewAdForParameters:(id)parameters ad BOOL isBiddingAd = [bidResponse al_isValidString]; NSString *adFormatLabel = adFormat.label; self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + self.bidResponse = bidResponse; [self log: @"Loading %@%@ ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), adFormatLabel, self.placementIdentifier]; if ( ![[VungleSDK sharedSDK] isInitialized] ) @@ -463,27 +427,20 @@ - (void)loadAdViewAdForParameters:(id)parameters ad [[VungleSDK sharedSDK] disableBannerRefresh]; - VungleAdSize adSize = [ALVungleMediationAdapter vungleBannerAdSizeFromFormat: adFormat]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] - || [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse withSize: adSize] ) - { - [self showAdViewAdForParameters: parameters - adFormat: adFormat - andNotify: delegate]; - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] - || [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier withSize: adSize] ) - { + // Not allowed to skip load ad even if the ad is cached. + // That will cause nurl missing issue. + + [self loadAdViewAdForParameters:parameters adFormat:adFormat adFormatLabel:adFormatLabel andNotify:delegate completion:^(NSString * placementID) { + self.router.adViewAdLoadCompletionBlock = nil; [self showAdViewAdForParameters: parameters adFormat: adFormat andNotify: delegate]; - return; - } - + }]; +} + +- (void)loadAdViewAdForParameters:(id)parameters adFormat:(MAAdFormat *)adFormat adFormatLabel:(NSString *)adFormatLabel andNotify:(id)delegate completion:(void (^)(NSString *))completion +{ + self.router.adViewAdLoadCompletionBlock = completion; NSError *error; BOOL isLoaded = [self loadAdForParameters: parameters adFormat: adFormat @@ -491,16 +448,11 @@ - (void)loadAdViewAdForParameters:(id)parameters ad if ( !isLoaded || error ) { + self.router.adViewAdLoadCompletionBlock = nil; MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; [self log: @"%@ ad failed to load with error: %@", adFormatLabel, error]; [delegate didFailToLoadAdViewAdWithError: adapterError]; } - else - { - [self showAdViewAdForParameters: parameters - adFormat: adFormat - andNotify: delegate]; - } } - (void)showAdViewAdForParameters:(id)parameters adFormat:(MAAdFormat *)adFormat andNotify:(id)delegate @@ -861,9 +813,13 @@ - (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable placementID:(NSString *)pla deferToNextMainQueueRunloop(^{ [self didLoadAdForPlacementIdentifier: placementID]; }); - + if ( self.adViewAdLoadCompletionBlock ) + { + self.adViewAdLoadCompletionBlock(placementID); + } return; } + self.adViewAdLoadCompletionBlock = nil; if ( error ) {