Skip to content

Commit

Permalink
Address Banner and MREC ad display issue. (#6)
Browse files Browse the repository at this point in the history
* Address Banner and MREC ad display issue.

This commit will update the show ad for Banner/Mrec to be
called after the ad finishes downloading the assets.
Also updates the finish display ad to be called on destroy.

IOS-5559
IOS-5560
  • Loading branch information
ManojBudumuru-vungle committed Feb 1, 2023
1 parent faf8447 commit e3562a5
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions Vungle/VungleAdapter/ALVungleMediationAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ - (void)didFailToDisplayAppOpenAdWithError:(MAAdapterError *)adapterError;
@end

@interface ALVungleMediationAdapterRouter : ALMediationAdapterRouter <VungleSDKDelegate, VungleSDKCreativeTracking, VungleSDKHBDelegate>
@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<NSString *, NSString *> *creativeIdentifiers;

Expand All @@ -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;
Expand Down Expand Up @@ -139,7 +140,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;
}

Expand Down Expand Up @@ -446,6 +455,7 @@ - (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)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] )
Expand Down Expand Up @@ -484,23 +494,29 @@ - (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)parameters ad
return;
}

[self loadAdViewAdForParameters:parameters adFormat:adFormat adFormatLabel:adFormatLabel andNotify:delegate completion:^(NSString * placementID) {
self.router.adViewAdLoadCompletionBlock = nil;
[self showAdViewAdForParameters: parameters
adFormat: adFormat
andNotify: delegate];
}];
}

- (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)parameters adFormat:(MAAdFormat *)adFormat adFormatLabel:(NSString *)adFormatLabel andNotify:(id<MAAdViewAdapterDelegate>)delegate completion:(void (^)(NSString *))completion
{
self.router.adViewAdLoadCompletionBlock = completion;
NSError *error;
BOOL isLoaded = [self loadAdForParameters: parameters
adFormat: adFormat
error: &error];

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<MAAdapterResponseParameters>)parameters adFormat:(MAAdFormat *)adFormat andNotify:(id<MAAdViewAdapterDelegate>)delegate
Expand Down Expand Up @@ -861,9 +877,13 @@ - (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable placementID:(NSString *)pla
deferToNextMainQueueRunloop(^{
[self didLoadAdForPlacementIdentifier: placementID];
});

if ( self.adViewAdLoadCompletionBlock )
{
self.adViewAdLoadCompletionBlock(placementID);
}
return;
}
self.adViewAdLoadCompletionBlock = nil;

if ( error )
{
Expand Down

0 comments on commit e3562a5

Please sign in to comment.