Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Banner and MREC ad display issue. #6

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions Vungle/VungleAdapter/ALVungleMediationAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ - (void)didFailToDisplayAppOpenAdWithError:(MAAdapterError *)adapterError;
@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(^adViewAdLoadCompletionBlock)(NSString *);
@property (nonatomic, assign, getter=hasGrantedReward) BOOL grantedReward;
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *creativeIdentifiers;

Expand All @@ -56,8 +57,9 @@ - (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;

@property (nonatomic, strong) NSMutableDictionary *adViewbidResponseDict;
// Native Ad Properties
@property (nonatomic, strong) VungleNativeAd *nativeAd;
@property (nonatomic, strong) ALVungleMediationAdapterNativeAdDelegate *nativeAdDelegate;
Expand Down Expand Up @@ -139,7 +141,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 @@ -444,8 +454,17 @@ - (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)parameters ad
{
NSString *bidResponse = parameters.bidResponse;
BOOL isBiddingAd = [bidResponse al_isValidString];
if ( isBiddingAd && bidResponse )
{
if ( !self.adViewbidResponseDict )
{
self.adViewbidResponseDict = [[NSMutableDictionary alloc] init];
}
self.adViewbidResponseDict[self.placementIdentifier] = bidResponse;
Copy link

@YueVungle YueVungle Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ManojBudumuru-vungle Tested on the device, for bidding banner, failed to load ad with the error:

2022-11-11 17:17:18.002401+0800 AppLovin MAX Demo App - ObjC[1526:55660] [AppLovinSdk] ERROR [ALMediationAdapterWrapper] Failed start loading [ALMediatedAdViewAd thirdPartyAdPlacementIdentifier=IAB_BANNER_1-6722317, adUnitIdentifier=55f1fdf557bea516, format=BANNER, networkName=Vungle] : *** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil
(lldb) po error
[MAError: code=-5001, message=MAX returned eligible ads from mediated networks, but all ads failed to load. Inspect -[MAError waterfall] for more info., mediatedNetworkErrorCode=-1, mediatedNetworkErrorMessage=]

Trough debugging, found that the self.placementIdentifier is nil when self.adViewbidResponseDict[self.placementIdentifier] = bidResponse;, we need to put self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; before self.adViewbidResponseDict[self.placementIdentifier] = bidResponse;

After put self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; before self.adViewbidResponseDict[self.placementIdentifier] = bidResponse; We can receive Bidding Banner ads:
ad

Thanks a lot. :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. i forgot to remove this. we dont need it.

}
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 +503,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 @@ -864,9 +889,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