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

[IOS-5813]Fix nurl not triggered issue #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
118 changes: 37 additions & 81 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 @@ -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;
}

Expand Down Expand Up @@ -184,23 +192,8 @@ - (void)loadInterstitialAdForParameters:(id<MAAdapterResponseParameters>)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
Expand Down Expand Up @@ -275,23 +268,8 @@ - (void)loadAppOpenAdForParameters:(id<MAAdapterResponseParameters>)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
Expand Down Expand Up @@ -366,23 +344,8 @@ - (void)loadRewardedAdForParameters:(id<MAAdapterResponseParameters>)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
Expand Down Expand Up @@ -446,6 +409,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 All @@ -463,44 +427,32 @@ - (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)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<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 +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 )
{
Expand Down