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-6797] Support in-feed Placement #17

Merged
merged 11 commits into from
Jul 30, 2024
139 changes: 80 additions & 59 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.3.1.0"
#define ADAPTER_VERSION @"7.4.0.0"

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

@interface ALVungleMediationAdapterAdViewDelegate : NSObject <VungleBannerDelegate>
@interface ALVungleMediationAdapterAdViewDelegate : NSObject <VungleBannerViewDelegate, VungleAdSizeDelegate>
@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter;
@property (nonatomic, strong) MAAdFormat *adFormat;
@property (nonatomic, strong) id<MAAdapterResponseParameters> parameters;
Expand Down Expand Up @@ -84,8 +84,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 @@ -173,7 +172,6 @@ - (void)destroy
self.adView.delegate = nil;
self.adView = nil;
self.adViewDelegate = nil;
self.adViewContainer = nil;

[self.nativeAd unregisterView];
self.nativeAd.delegate = nil;
Expand All @@ -194,6 +192,8 @@ - (void)collectSignalWithParameters:(id<MASignalCollectionParameters>)parameters

NSString *signal = [VungleAds getBiddingToken];
[delegate didCollectSignal: signal];

// TODO: We might need to send adaptive banner's width and height as extra param here.
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
}

#pragma mark - MAInterstitialAdapter Methods
Expand Down Expand Up @@ -402,17 +402,16 @@ - (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];
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
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.adSizeDelegate = self.adViewDelegate;

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

- (BannerSize)adSizeFromAdFormat:(MAAdFormat *)adFormat
- (VungleAdSize *)adSizeFromAdFormat:(MAAdFormat *)adFormat
parameters:(id<MAAdapterParameters>)parameters
{
if ( adFormat == MAAdFormat.banner )
BOOL isAdaptiveBanner = parameters.localExtraParameters[@"adaptive_banner"];
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
if ( isAdaptiveBanner )
{
return BannerSizeRegular;
return [VungleAdSize VungleAdSizeWithWidth:[self adaptiveBannerWidthFromParameters: parameters]];
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
}
else if ( adFormat == MAAdFormat.leader )
{
return BannerSizeLeaderboard;
}
else if ( adFormat == MAAdFormat.mrec )
else
{
return BannerSizeMrec;
if ( adFormat == MAAdFormat.banner )
{
return [VungleAdSize VungleAdSizeBannerRegular];
}
else if ( adFormat == MAAdFormat.leader )
{
return [VungleAdSize VungleAdSizeLeaderboard];
}
else if ( adFormat == MAAdFormat.mrec )
{
return [VungleAdSize VungleAdSizeMREC];
}
else
{
[NSException raise: NSInvalidArgumentException format: @"Unsupported ad format: %@", adFormat];
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
return [VungleAdSize VungleAdSizeBannerRegular];
}
}
else
}

- (CGFloat)adaptiveBannerWidthFromParameters:(id<MAAdapterParameters>)parameters
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
{
NSNumber *customWidth = [parameters.localExtraParameters al_numberForKey: @"adaptive_banner_width"];
if ( customWidth != nil )
{
[NSException raise: NSInvalidArgumentException format: @"Unsupported ad format: %@", adFormat];
return BannerSizeRegular;
return customWidth.floatValue;
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
}

UIViewController *viewController = [ALUtils topViewControllerFromKeyWindow];
UIWindow *window = viewController.view.window;
CGRect frame = UIEdgeInsetsInsetRect(window.frame, window.safeAreaInsets);

return CGRectGetWidth(frame);
}

+ (MAAdapterError *)toMaxError:(nullable NSError *)vungleError isAdPresentError:(BOOL)adPresentError
Expand Down Expand Up @@ -893,81 +916,79 @@ - (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter
return self;
}

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

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

NSMutableDictionary *extraInfo = [NSMutableDictionary dictionaryWithCapacity: 3];

NSString *creativeIdentifier = bannerView.creativeId;
if ( [creativeIdentifier al_isValidString] )
{
[self.delegate didLoadAdForAdView: self.parentAdapter.adViewContainer withExtraInfo: @{@"creative_id" : creativeIdentifier}];
extraInfo[@"creative_id"] = creativeIdentifier;
}
else

// TODO: We are confirming with MAX if we need to pass bannerView's w and h through this callback or not.
CGSize adSize = bannerView.vungleAdSize.size;
if ( !CGSizeEqualToSize(CGSizeZero, adSize) )
{
[self.delegate didLoadAdForAdView: self.parentAdapter.adViewContainer];
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
extraInfo[@"ad_width"] = @(adSize.width);
extraInfo[@"ad_height"] = @(adSize.height);
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
}

if ( [banner canPlayAd] )
{
[banner presentOn: self.parentAdapter.adViewContainer];
}
else
{
[self.parentAdapter log: @"Failed to load ad view ad: ad not ready"];
[self.delegate didFailToLoadAdViewAdWithError: MAAdapterError.adNotReady];
}
[self.delegate performSelector: @selector(didLoadAdForAdView:withExtraInfo:)
withObject: bannerView
withObject: extraInfo];
}

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

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

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

- (void)bannerAdDidTrackImpression:(VungleBanner *)banner
- (void)bannerAdDidTrackImpression:(VungleBannerView *)bannerView
{
[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];
Copy link

@YueVungle YueVungle May 21, 2024

Choose a reason for hiding this comment

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

We will not notify any ad presenting error to the mediation, right? or Might we move self.delegate didFailToDisplayAdViewAdWithError: adapterError]; to bannerAdDidFail:withError: delegate method? Thanks a lot. :)

Copy link
Author

Choose a reason for hiding this comment

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

The callback method here has been changed from bannerAdDidFailToPresent to bannerAdWillClose.
We don't have bannerAdDidFailToPresent anymore with VungleBannerView class.

Copy link
Author

Choose a reason for hiding this comment

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

Now, it's taken care at bannerAdDidFail callback.

Choose a reason for hiding this comment

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

u need to move this logic into bannerAdDidFail: callback.

Copy link
Author

Choose a reason for hiding this comment

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

I have below in bannerAdDidFail.

    MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error isAdPresentError: NO];
    [self.parentAdapter log: @"AdView failed to load with error: %@", adapterError];
    [self.delegate didFailToLoadAdViewAdWithError: adapterError];

Do you know if we need isAdPresentError: NO or isAdPresentError: YES ?

Choose a reason for hiding this comment

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

its based on present error or load error.

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

[self.parentAdapter log: @"AdView ad will close %@", bannerView.placementId];

Choose a reason for hiding this comment

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

Why remove the toMaxError line?

Copy link
Author

Choose a reason for hiding this comment

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

The callback method here has been changed from bannerAdDidFailToPresent to bannerAdWillClose.
So, no error.

Copy link
Author

Choose a reason for hiding this comment

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

Now, it's taken care at bannerAdDidFail callback.

}

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

- (void)bannerAdDidClose:(VungleBanner *)banner
- (void)adViewWillChangeToSize:(VungleBannerView * _Nonnull)bannerView :(VungleAdSize * _Nonnull)size
ashinagawa marked this conversation as resolved.
Show resolved Hide resolved
{
[self.parentAdapter log: @"AdView ad hidden %@", banner.placementId];
[self.delegate didHideAdViewAd];
[self.parentAdapter log: @"AdView will change size: %@", bannerView.placementId];
}

@end
Expand Down