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

7.4.0 release #355

Open
wants to merge 4 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
154 changes: 93 additions & 61 deletions Vungle/VungleAdapter/ALVungleMediationAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "ALVungleMediationAdapter.h"
#import <VungleAdsSDK/VungleAdsSDK.h>

#define ADAPTER_VERSION @"7.4.0.0"
#define ADAPTER_VERSION @"7.4.1.0"

@interface ALVungleMediationAdapterInterstitialAdDelegate : NSObject <VungleInterstitialDelegate>
@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter;
Expand All @@ -30,11 +30,12 @@ @interface ALVungleMediationAdapterRewardedAdDelegate : NSObject <VungleRewarded
- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id<MARewardedAdapterDelegate>)delegate;
@end

@interface ALVungleMediationAdapterAdViewDelegate : NSObject <VungleBannerDelegate>
@interface ALVungleMediationAdapterAdViewDelegate : NSObject <VungleBannerViewDelegate>
@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter;
@property (nonatomic, strong) MAAdFormat *adFormat;
@property (nonatomic, strong) id<MAAdapterResponseParameters> parameters;
@property (nonatomic, strong) id<MAAdViewAdapterDelegate> delegate;
@property (nonatomic, assign) BOOL isAdloadSuccess;
- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter
format:(MAAdFormat *)adFormat
parameters:(id<MAAdapterResponseParameters>)parameters
Expand Down Expand Up @@ -84,8 +85,7 @@ @interface ALVungleMediationAdapter ()
@property (nonatomic, strong) ALVungleMediationAdapterRewardedAdDelegate *rewardedAdDelegate;

// AdView
@property (nonatomic, strong) VungleBanner *adView;
@property (nonatomic, strong) UIView *adViewContainer;
@property (nonatomic, strong) VungleBannerView *adView;
@property (nonatomic, strong) ALVungleMediationAdapterAdViewDelegate *adViewDelegate;

// Native Ad
Expand Down Expand Up @@ -124,8 +124,6 @@ - (void)initializeWithParameters:(id<MAAdapterInitializationParameters>)paramete
[VungleAds initWithAppId: appID completion:^(NSError * _Nullable error) {
if ( error )
{
[ALVungleInitialized set: NO];

[self log: @"Vungle SDK failed to initialize with error: %@", error];

ALVungleIntializationStatus = MAAdapterInitializationStatusInitializedFailure;
Expand Down Expand Up @@ -175,7 +173,6 @@ - (void)destroy
self.adView.delegate = nil;
self.adView = nil;
self.adViewDelegate = nil;
self.adViewContainer = nil;

[self.nativeAd unregisterView];
self.nativeAd.delegate = nil;
Expand Down Expand Up @@ -404,17 +401,13 @@ - (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)parameters ad
}
else
{
BannerSize adSize = [self adSizeFromAdFormat: adFormat];

self.adView = [[VungleBanner alloc] initWithPlacementId: placementIdentifier size: adSize];
VungleAdSize *adSize = [self adSizeFromAdFormat: adFormat parameters:parameters];
self.adView = [[VungleBannerView alloc] initWithPlacementId: placementIdentifier vungleAdSize: adSize];
self.adViewDelegate = [[ALVungleMediationAdapterAdViewDelegate alloc] initWithParentAdapter: self
format: adFormat
parameters: parameters
andNotify: delegate];
self.adView.delegate = self.adViewDelegate;

self.adViewContainer = [[UIView alloc] initWithFrame: (CGRect) { CGPointZero, adFormat.size }];

[self.adView load: bidResponse];
}
}
Expand Down Expand Up @@ -525,24 +518,34 @@ - (void)loadVungleNativeAdForParameters:(id<MAAdapterResponseParameters>)paramet
return clickableViews;
}

- (BannerSize)adSizeFromAdFormat:(MAAdFormat *)adFormat
- (VungleAdSize *)adSizeFromAdFormat:(MAAdFormat *)adFormat
parameters:(id<MAAdapterParameters>)parameters
{
if ( adFormat == MAAdFormat.banner )
if ([parameters.localExtraParameters al_boolForKey: @"adaptive_banner"]) {
NSNumber *customWidth = [parameters.localExtraParameters al_numberForKey: @"adaptive_banner_width"];
// Need to check `customHeight` to determine if the request is for Custom or Adaptive.
NSNumber *customHeight = [parameters.localExtraParameters al_numberForKey: @"adaptive_banner_height"];
if (!customHeight) {
customHeight = 0;
}
return [VungleAdSize VungleAdSizeFromCGSize:(CGSizeMake(customWidth.floatValue, customHeight.floatValue))];
}
else if ( adFormat == MAAdFormat.banner )
{
return BannerSizeRegular;
return [VungleAdSize VungleAdSizeBannerRegular];
}
else if ( adFormat == MAAdFormat.leader )
{
return BannerSizeLeaderboard;
return [VungleAdSize VungleAdSizeLeaderboard];
}
else if ( adFormat == MAAdFormat.mrec )
{
return BannerSizeMrec;
return [VungleAdSize VungleAdSizeMREC];
}
else
{
[NSException raise: NSInvalidArgumentException format: @"Unsupported ad format: %@", adFormat];
return BannerSizeRegular;
return [VungleAdSize VungleAdSizeBannerRegular];
}
}

Expand Down Expand Up @@ -896,84 +899,95 @@ - (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter
self.adFormat = adFormat;
self.parameters = parameters;
self.delegate = delegate;
self.isAdloadSuccess = NO;
}
return self;
}

- (void)bannerAdDidLoad:(VungleBanner *)banner
- (void)bannerAdDidLoad:(VungleBannerView *)bannerView
{
[self.parentAdapter log: @"AdView loaded: %@", banner.placementId];

NSString *creativeIdentifier = banner.creativeId;
if ( [creativeIdentifier al_isValidString] )
[self.parentAdapter log: @"AdView loaded: %@", bannerView.placementId];

self.isAdloadSuccess = YES;

if ( ALSdk.versionCode >= 6150000 )
{
[self.delegate didLoadAdForAdView: self.parentAdapter.adViewContainer withExtraInfo: @{@"creative_id" : creativeIdentifier}];
NSMutableDictionary *extraInfo = [NSMutableDictionary dictionaryWithCapacity: 3];

NSString *creativeIdentifier = bannerView.creativeId;
if ( [creativeIdentifier al_isValidString] )
{
extraInfo[@"creative_id"] = creativeIdentifier;

}

CGSize adSize = [bannerView getBannerSize];
if ( !CGSizeEqualToSize(CGSizeZero, adSize) )
{
extraInfo[@"ad_width"] = @(adSize.width);
extraInfo[@"ad_height"] = @(adSize.height);

}

[self.delegate performSelector: @selector(didLoadAdForAdView:withExtraInfo:)
withObject: bannerView
withObject: extraInfo];
}
else
{
[self.delegate didLoadAdForAdView: self.parentAdapter.adViewContainer];
else {
[self.delegate didLoadAdForAdView: bannerView];
}

if ( [banner canPlayAd] )
}

- (void)bannerAdDidFail:(VungleBannerView *)bannerView withError:(NSError *)error
{
MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error isAdPresentError: self.isAdloadSuccess];
if ( self.isAdloadSuccess )
{
[banner presentOn: self.parentAdapter.adViewContainer];
[self.parentAdapter log: @"AdView failed to display with error: %@", adapterError];
[self.delegate didFailToDisplayAdViewAdWithError: adapterError];
}
else
{
[self.parentAdapter log: @"Failed to load ad view ad: ad not ready"];
[self.delegate didFailToLoadAdViewAdWithError: MAAdapterError.adNotReady];
[self.parentAdapter log: @"AdView failed to load with error: %@", adapterError];
[self.delegate didFailToLoadAdViewAdWithError: adapterError];
}
}

- (void)bannerAdDidFailToLoad:(VungleBanner *)banner withError:(NSError *)error
- (void)bannerAdWillPresent:(VungleBannerView *)bannerView
{
MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error isAdPresentError: NO];
[self.parentAdapter log: @"AdView failed to load with error: %@", adapterError];
[self.delegate didFailToLoadAdViewAdWithError: adapterError];
[self.parentAdapter log: @"AdView ad will present %@", bannerView.placementId];
}

- (void)bannerAdWillPresent:(VungleBanner *)banner
- (void)bannerAdDidPresent:(VungleBannerView *)bannerView
{
[self.parentAdapter log: @"AdView ad will present %@", banner.placementId];
[self.parentAdapter log: @"AdView ad shown %@", bannerView.placementId];
}

- (void)bannerAdDidPresent:(VungleBanner *)banner
- (void)bannerAdDidTrackImpression:(VungleBannerView *)bannerView
{
[self.parentAdapter log: @"AdView ad shown %@", banner.placementId];
}

- (void)bannerAdDidTrackImpression:(VungleBanner *)banner
{
[self.parentAdapter log: @"AdView ad impression tracked %@", banner.placementId];
[self.parentAdapter log: @"AdView ad impression tracked %@", bannerView.placementId];
[self.delegate didDisplayAdViewAd];
}

- (void)bannerAdDidClick:(VungleBanner *)banner
- (void)bannerAdDidClick:(VungleBannerView *)bannerView
{
[self.parentAdapter log: @"AdView ad clicked %@", banner.placementId];
[self.parentAdapter log: @"AdView ad clicked %@", bannerView.placementId];
[self.delegate didClickAdViewAd];
}

- (void)bannerAdWillLeaveApplication:(VungleBanner *)banner
- (void)bannerAdWillLeaveApplication:(VungleBannerView *)bannerView
{
[self.parentAdapter log: @"AdView ad will leave application %@", banner.placementId];
[self.parentAdapter log: @"AdView ad will leave application %@", bannerView.placementId];
}

- (void)bannerAdDidFailToPresent:(VungleBanner *)banner withError:(NSError *)error
- (void)bannerAdWillClose:(VungleBannerView *)bannerView
{
MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error isAdPresentError: YES];
[self.parentAdapter log: @"AdView ad failed to present with error: %@", adapterError];
[self.delegate didFailToDisplayAdViewAdWithError: adapterError];
[self.parentAdapter log: @"AdView ad will close %@", bannerView.placementId];
}

- (void)bannerAdWillClose:(VungleBanner *)banner
- (void)bannerAdDidClose:(VungleBannerView *)bannerView
{
[self.parentAdapter log: @"AdView ad will close %@", banner.placementId];
}

- (void)bannerAdDidClose:(VungleBanner *)banner
{
[self.parentAdapter log: @"AdView ad hidden %@", banner.placementId];
[self.parentAdapter log: @"AdView ad hidden %@", bannerView.placementId];
[self.delegate didHideAdViewAd];
}

Expand Down Expand Up @@ -1018,6 +1032,9 @@ - (void)nativeAdDidLoad:(VungleNative *)nativeAd

[self.parentAdapter log: @"Native %@ ad loaded: %@", self.adFormat, self.placementIdentifier];

// returns aspect ratio of media to be displayed. Will return 0.0 by default
CGFloat mediaContentAspectRatio = [nativeAd getMediaAspectRatio];

dispatchOnMainQueue(^{
MediaView *mediaView = [[MediaView alloc] init];

Expand All @@ -1035,6 +1052,12 @@ - (void)nativeAdDidLoad:(VungleNative *)nativeAd
{
[builder performSelector: @selector(setAdvertiser:) withObject: nativeAd.sponsoredText];
}
// Introduced in 11.4.0
if ( [builder respondsToSelector: @selector(setMediaContentAspectRatio:)] )
{
[builder performSelector: @selector(setMediaContentAspectRatio:) withObject: @(mediaContentAspectRatio)];
}

#pragma clang diagnostic pop
}];

Expand Down Expand Up @@ -1132,6 +1155,9 @@ - (void)nativeAdDidLoad:(VungleNative *)nativeAd

[self.parentAdapter log: @"Native ad loaded: %@", self.placementIdentifier];

// returns aspect ratio of media to be displayed. Will return 0.0 by default
CGFloat mediaContentAspectRatio = [nativeAd getMediaAspectRatio];

dispatchOnMainQueue(^{
MediaView *mediaView = [[MediaView alloc] init];

Expand All @@ -1149,6 +1175,12 @@ - (void)nativeAdDidLoad:(VungleNative *)nativeAd
{
[builder performSelector: @selector(setAdvertiser:) withObject: nativeAd.sponsoredText];
}

// Introduced in 11.4.0
if ( [builder respondsToSelector: @selector(setMediaContentAspectRatio:)] )
{
[builder performSelector: @selector(setMediaContentAspectRatio:) withObject: @(mediaContentAspectRatio)];
}
#pragma clang diagnostic pop
}];

Expand Down