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
124 changes: 68 additions & 56 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,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 @@ -173,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 @@ -402,17 +401,14 @@ - (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 @@ -518,24 +514,32 @@ - (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 al_boolForKey: @"adaptive_banner"];
NSNumber *customWidth = [parameters.localExtraParameters al_numberForKey: @"adaptive_banner_width"] ? : 0;
NSNumber *customHight = [parameters.localExtraParameters al_numberForKey: @"adaptive_banner_height"] ? : 0;

if (!isAdaptiveBanner && customWidth && customWidth) {

Choose a reason for hiding this comment

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

Can u move the line 521 and 522 inside here. and since u ave a default value as 0 which our sdk support u dont need to check customWidth && customWidth in if block.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. Thanks!
Updated.

return [VungleAdSize VungleAdSizeFromCGSize:(CGSizeMake(customWidth.floatValue, customHight.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 @@ -889,84 +893,92 @@ - (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;
[self.parentAdapter log: @"AdView loaded: %@", bannerView.placementId];

self.isAdloadSuccess = YES;
NSMutableDictionary *extraInfo = [NSMutableDictionary dictionaryWithCapacity: 3];
BOOL isExtraInfo = NO;

Choose a reason for hiding this comment

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

i think MAX will comment on this.
so i think u can just do what google dose.
https://github.com/AppLovin/AppLovin-MAX-SDK-iOS/blob/master/Google/GoogleAdapter/ALGoogleAdViewDelegate.m#L37

Check for ALSdk.versionCode >= 6150000 for if else. Thanks @ashinagawa

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

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

CGSize adSize = [bannerView getBannerSize];
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
isExtraInfo = YES;
}

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];
if (isExtraInfo) {
[self.delegate performSelector: @selector(didLoadAdForAdView:withExtraInfo:)
withObject: bannerView
withObject: extraInfo];
} else {
[self.delegate didLoadAdForAdView: bannerView];
}
}

- (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];
if ( self.isAdloadSuccess )
{
[self.parentAdapter log: @"AdView failed to display with error: %@", adapterError];
[self.delegate didFailToDisplayAdViewAdWithError: adapterError];
}
else
{
[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
{
[self.parentAdapter log: @"AdView ad will leave application %@", banner.placementId];
}

- (void)bannerAdDidFailToPresent:(VungleBanner *)banner withError:(NSError *)error
- (void)bannerAdWillLeaveApplication:(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 leave application %@", bannerView.placementId];
}

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

Expand Down