diff --git a/Vungle/VungleAdapter/ALVungleMediationAdapter.m b/Vungle/VungleAdapter/ALVungleMediationAdapter.m index 3e17e9aa5b..ce57d16056 100644 --- a/Vungle/VungleAdapter/ALVungleMediationAdapter.m +++ b/Vungle/VungleAdapter/ALVungleMediationAdapter.m @@ -9,7 +9,7 @@ #import "ALVungleMediationAdapter.h" #import -#define ADAPTER_VERSION @"7.4.0.0" +#define ADAPTER_VERSION @"7.4.1.0" @interface ALVungleMediationAdapterInterstitialAdDelegate : NSObject @property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; @@ -30,11 +30,12 @@ @interface ALVungleMediationAdapterRewardedAdDelegate : NSObject )delegate; @end -@interface ALVungleMediationAdapterAdViewDelegate : NSObject +@interface ALVungleMediationAdapterAdViewDelegate : NSObject @property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; @property (nonatomic, strong) MAAdFormat *adFormat; @property (nonatomic, strong) id parameters; @property (nonatomic, strong) id delegate; +@property (nonatomic, assign) BOOL isAdloadSuccess; - (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter format:(MAAdFormat *)adFormat parameters:(id)parameters @@ -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 @@ -124,8 +124,6 @@ - (void)initializeWithParameters:(id)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; @@ -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; @@ -404,17 +401,13 @@ - (void)loadAdViewAdForParameters:(id)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]; } } @@ -525,24 +518,34 @@ - (void)loadVungleNativeAdForParameters:(id)paramet return clickableViews; } -- (BannerSize)adSizeFromAdFormat:(MAAdFormat *)adFormat +- (VungleAdSize *)adSizeFromAdFormat:(MAAdFormat *)adFormat + parameters:(id)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]; } } @@ -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]; } @@ -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]; @@ -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 }]; @@ -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]; @@ -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 }];