Skip to content

Commit

Permalink
BidMachine/3.0.1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AppLovin-Mobile-Engineering committed Nov 12, 2024
1 parent 10f8dea commit 2aede06
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 13 deletions.
4 changes: 2 additions & 2 deletions BidMachine/AppLovinMediationBidMachineAdapter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|

s.authors = 'AppLovin Corporation'
s.name = 'AppLovinMediationBidMachineAdapter'
s.version = '3.0.1.0.0'
s.version = '3.0.1.0.1'
s.platform = :ios, '12.0'
s.summary = 'BidMachine adapter used for mediation with the AppLovin MAX SDK'
s.homepage = "https://github.com/CocoaPods/Specs/search?o=desc&q=#{s.name}&s=indexed"
Expand All @@ -26,7 +26,7 @@ s.source =

s.vendored_frameworks = "#{s.name}-#{s.version}/#{s.name}.xcframework"

s.dependency 'BidMachine', '= 3.0.1'
s.dependency 'BidMachine', '= {ADAPTER_SDK_VERSION}'
s.dependency 'AppLovinSDK', '>= 13.0.0'
s.swift_version = '5.1'

Expand Down
117 changes: 106 additions & 11 deletions BidMachine/BidMachineAdapter/ALBidMachineMediationAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
#import "ALBidMachineMediationAdapter.h"
#import <BidMachine/BidMachine.h>

#define ADAPTER_VERSION @"3.0.1.0.0"
#define ADAPTER_VERSION @"3.0.1.0.1"

#define TITLE_LABEL_TAG 1
#define MEDIA_VIEW_CONTAINER_TAG 2
#define ICON_VIEW_TAG 3
#define BODY_VIEW_TAG 4
#define CALL_TO_ACTION_VIEW_TAG 5
#define ADVERTISER_VIEW_TAG 8

@interface ALBidMachineInterstitialDelegate : NSObject <BidMachineAdDelegate>
@property (nonatomic, weak) ALBidMachineMediationAdapter *parentAdapter;
Expand Down Expand Up @@ -55,6 +62,15 @@ @interface MABidMachineNativeAdRendering : NSObject <BidMachineNativeAdRendering
- (instancetype)initWithNativeAdView:(MANativeAdView *)adView;
@end

@interface MABidMachineNativeAdPluginRendering : NSObject <BidMachineNativeAdRendering>
@property (nonatomic, strong) UILabel *callToActionLabel;
@property (nonatomic, strong) UILabel *descriptionLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UIView *mediaContainerView;
@property (nonatomic, weak) UIView *adChoiceView;
@end

@interface ALBidMachineMediationAdapter ()
@property (nonatomic, strong) BidMachineInterstitial *interstitialAd;
@property (nonatomic, strong) BidMachineRewarded *rewardedAd;
Expand Down Expand Up @@ -153,6 +169,14 @@ - (void)collectSignalWithParameters:(id<MASignalCollectionParameters>)parameters
[self updateSettings: parameters];

BidMachinePlacementFormat bidMachinePlacementFormat = [self bidMachinePlacementFormatFromAdFormat: parameters.adFormat];
if ( bidMachinePlacementFormat == BidMachinePlacementFormatUnknown )
{
[self log: @"Signal collection failed with error: Unsupported ad format: %@", parameters.adFormat];
[delegate didFailToCollectSignalWithErrorMessage: [NSString stringWithFormat: @"Unsupported ad format: %@", parameters.adFormat]];

return;
}

[BidMachineSdk.shared tokenWith: bidMachinePlacementFormat completion:^(NSString *_Nullable signal) {
[self log: @"Signal collection successful with%@ valid signal", [signal al_isValidString] ? @"" : @"out"];
[delegate didCollectSignal: signal];
Expand Down Expand Up @@ -334,6 +358,15 @@ - (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)parameters
[self updateSettings: parameters];

BidMachinePlacementFormat format = [self bidMachinePlacementFormatFromAdFormat: adFormat];
if ( format == BidMachinePlacementFormatUnknown )
{
MAAdapterError *adapterError = [MAAdapterError errorWithCode: MAAdapterError.errorCodeInvalidConfiguration
errorString: [NSString stringWithFormat: @"Unsupported ad format: %@", adFormat]];
[self log: @"AdView ad failed to load with error: %@", adapterError];
[delegate didFailToLoadAdViewAdWithError: adapterError];

return;
}

NSError *configurationError = nil;
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration: format error: &configurationError];
Expand Down Expand Up @@ -522,7 +555,6 @@ - (BidMachinePlacementFormat)bidMachinePlacementFormatFromAdFormat:(MAAdFormat *
}
else
{
[NSException raise: NSInvalidArgumentException format: @"Invalid ad format: %@", adFormat];
return BidMachinePlacementFormatUnknown;
}
}
Expand Down Expand Up @@ -643,6 +675,10 @@ - (UIView *)adChoiceView

@end

@implementation MABidMachineNativeAdPluginRendering

@end

@implementation ALBidMachineInterstitialDelegate

- (instancetype)initWithParentAdapter:(ALBidMachineMediationAdapter *)parentAdapter andNotify:(id<MAInterstitialAdapterDelegate>)delegate
Expand Down Expand Up @@ -988,8 +1024,9 @@ - (void)didLoadAd:(id<BidMachineAdProtocol>)ad
if ( nativeAd.main && [nativeAd.main al_isValidURL] )
{
[self.parentAdapter log: @"Fetching native ad main image: %@", nativeAd.main];
mainImageView = [[UIImageView alloc] init];
[self.parentAdapter loadImageForURLString: nativeAd.main group: group successHandler:^(UIImage *image) {
mainImageView = [[UIImageView alloc] initWithImage: image];
mainImageView.image = image;
mainImage = [[MANativeAdImage alloc] initWithImage: image];
}];
}
Expand All @@ -1006,10 +1043,7 @@ - (void)didLoadAd:(id<BidMachineAdProtocol>)ad
builder.body = nativeAd.body;
builder.callToAction = nativeAd.cta;
builder.icon = iconImage;
if ( ALSdk.versionCode >= 11040299 )
{
[builder performSelector: @selector(setMainImage:) withObject: mainImage];
}
builder.mainImage = mainImage;
builder.mediaView = mainImageView;
}];

Expand Down Expand Up @@ -1108,10 +1142,55 @@ - (BOOL)prepareForInteractionClickableViews:(NSArray<UIView *> *)clickableViews
NSError *error = nil;

[self.parentAdapter d: @"Preparing views for interaction: %@ with container: %@", clickableViews, container];

MABidMachineNativeAdRendering *adRendering = [[MABidMachineNativeAdRendering alloc] initWithNativeAdView: container];
self.parentAdapter.nativeAd.controller = [ALUtils topViewControllerFromKeyWindow];
[self.parentAdapter.nativeAd presentAd: container : adRendering error: &error];

// Native integrations
if ( [container isKindOfClass: [MANativeAdView class]] )
{
MABidMachineNativeAdRendering *adRendering = [[MABidMachineNativeAdRendering alloc] initWithNativeAdView: container];
self.parentAdapter.nativeAd.controller = [ALUtils topViewControllerFromKeyWindow];
[self.parentAdapter.nativeAd presentAd: container : adRendering error: &error];
}
// Plugins
else
{
NSMutableArray *assetsForInteraction = [NSMutableArray array];
MABidMachineNativeAdPluginRendering *adPluginRendering = [[MABidMachineNativeAdPluginRendering alloc] init];

for ( UIView *view in clickableViews )
{
if ( view.tag == TITLE_LABEL_TAG )
{
[assetsForInteraction addObject: @(BidMachineNativeAdRenderingAssetTypeTitleLabel)];
adPluginRendering.titleLabel = [self bidMachineAssetViewOfClass: [UILabel class] forParent: view];
}
else if ( view.tag == MEDIA_VIEW_CONTAINER_TAG )
{
[assetsForInteraction addObject: @(BidMachineNativeAdRenderingAssetTypeMediaContainerView)];
adPluginRendering.mediaContainerView = view;
}
else if ( view.tag == ICON_VIEW_TAG )
{
if ( [view isKindOfClass: [UIImageView class]] )
{
[assetsForInteraction addObject: @(BidMachineNativeAdRenderingAssetTypeIconView)];
adPluginRendering.iconView = (UIImageView *) view;
}
}
else if ( view.tag == BODY_VIEW_TAG )
{
[assetsForInteraction addObject: @(BidMachineNativeAdRenderingAssetTypeDescriptionLabel)];
adPluginRendering.descriptionLabel = [self bidMachineAssetViewOfClass: [UILabel class] forParent: view];
}
else if ( view.tag == CALL_TO_ACTION_VIEW_TAG )
{
[assetsForInteraction addObject: @(BidMachineNativeAdRenderingAssetTypeCallToActionLabel)];
adPluginRendering.callToActionLabel = [self bidMachineAssetViewOfClass: [UILabel class] forParent: view];
}
}

[self.parentAdapter.nativeAd registerAssetsForInteraction: assetsForInteraction];
[self.parentAdapter.nativeAd presentAd: container : adPluginRendering error: &error];
}

if ( error )
{
Expand All @@ -1122,4 +1201,20 @@ - (BOOL)prepareForInteractionClickableViews:(NSArray<UIView *> *)clickableViews
return YES;
}

/**
* Creates a dummy asset view based on BidMachine API class requirements and the asset view type.
*/
- (id)bidMachineAssetViewOfClass:(Class)aClass forParent:(UIView *)parentView
{
UIView *assetView = [[aClass alloc] init];

// Set the view's alpha to make it essentially invisible but interactable, as the plugin's asset view manages actual content presentation.
assetView.alpha = 0.011f;

[parentView addSubview: assetView];
[assetView al_pinToSuperview];

return assetView;
}

@end
5 changes: 5 additions & 0 deletions BidMachine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.0.1.0.1
* Add support for native ads in external plugins (e.g. React Native / Flutter).
* Simplified API calls by removing selector checks; direct API calls are now safe with the updated min SDK version.
* Removed exception throwing if unable to map ad format to that of the network's.

## 3.0.1.0.0
* Certified with BidMachine SDK 3.0.1.

Expand Down

0 comments on commit 2aede06

Please sign in to comment.