Skip to content

Commit

Permalink
InMobi/10.0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
prod-applovin-deploy committed Mar 30, 2022
1 parent a5faae6 commit 2f4fe77
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 4 deletions.
2 changes: 1 addition & 1 deletion InMobi/AppLovinMediationInMobiAdapter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ s.authors =
'AppLovin Corporation' => '[email protected]'
}
s.name = 'AppLovinMediationInMobiAdapter'
s.version = '10.0.2.1'
s.version = '10.0.2.2'
s.platform = :ios, '9.0'
s.summary = 'InMobi 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 Down
3 changes: 3 additions & 0 deletions InMobi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 10.0.2.2
* Add support for passing native ads.

## 10.0.2.1
* Add support for passing in a presenting view controller.

Expand Down
251 changes: 248 additions & 3 deletions InMobi/InMobiAdapter/ALInMobiMediationAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "ALInMobiMediationAdapter.h"
#import <InMobiSDK/InMobiSDK.h>

#define ADAPTER_VERSION @"10.0.2.1"
#define ADAPTER_VERSION @"10.0.2.2"

/**
* Dedicated delegate object for InMobi AdView ads.
Expand Down Expand Up @@ -51,6 +51,30 @@ - (instancetype)init NS_UNAVAILABLE;

@end

/**
* Dedicated delegate object for InMobi native ads.
*/
@interface ALInMobiMediationAdapterNativeAdDelegate : NSObject<IMNativeDelegate>

@property (nonatomic, weak) ALInMobiMediationAdapter *parentAdapter;
@property (nonatomic, strong) id<MANativeAdAdapterDelegate> delegate;
@property (nonatomic, strong) NSDictionary<NSString *, id> *serverParameters;
@property (nonatomic, strong) NSString *placementId;

- (instancetype)initWithParentAdapter:(ALInMobiMediationAdapter *)parentAdapter parameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MANativeAdAdapterDelegate>)delegate;
- (instancetype)init NS_UNAVAILABLE;

@end

@interface MAInMobiNativeAd : MANativeAd
@property (nonatomic, weak) ALInMobiMediationAdapter *parentAdapter;
@property (nonatomic, strong) id<MANativeAdAdapterDelegate> delegate;
- (instancetype)initWithParentAdapter:(ALInMobiMediationAdapter *)parentAdapter
andNotify:(id<MANativeAdAdapterDelegate>)delegate
builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock;
- (instancetype)initWithFormat:(MAAdFormat *)format builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock NS_UNAVAILABLE;
@end

@interface ALInMobiMediationAdapter()

// AdView
Expand All @@ -65,6 +89,15 @@ @interface ALInMobiMediationAdapter()
@property (nonatomic, strong) IMInterstitial *rewardedAd;
@property (nonatomic, strong) ALInMobiMediationAdapterRewardedAdDelegate *rewardedAdDelegate;

// Native
@property (nonatomic, strong) IMNative *nativeAd;
@property (nonatomic, strong) ALInMobiMediationAdapterNativeAdDelegate *nativeAdDelegate;
@property (nonatomic, strong) UITapGestureRecognizer *titleGestureRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *advertiserGestureRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *bodyGestureRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *iconGestureRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *ctaGestureRecognizer;

@end

@implementation ALInMobiMediationAdapter
Expand Down Expand Up @@ -132,11 +165,14 @@ - (void)destroy
self.adView.delegate = nil;
self.adViewDelegate = nil;

self.interstitialAd.delegate = nil;
self.interstitialAd = nil;
self.interstitialAdDelegate = nil;

self.rewardedAd.delegate = nil;
self.rewardedAd = nil;
self.rewardedAdDelegate = nil;

self.nativeAd = nil;
self.nativeAdDelegate = nil;
}

#pragma mark - Signal Collection
Expand Down Expand Up @@ -236,6 +272,35 @@ - (void)showRewardedAdForParameters:(id<MAAdapterResponseParameters>)parameters
}
}

#pragma mark - Native Adapter

- (void)loadNativeAdForParameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MANativeAdAdapterDelegate>)delegate
{
long long placementId = parameters.thirdPartyAdPlacementIdentifier.longLongValue;
BOOL isBiddingAd = [parameters.bidResponse al_isValidString];

[self log: @"Loading %@native ad for placement: %lld...", ( isBiddingAd ? @"bidding " : @"" ), placementId];

self.nativeAdDelegate = [[ALInMobiMediationAdapterNativeAdDelegate alloc] initWithParentAdapter: self
parameters: parameters
andNotify: delegate];
self.nativeAd = [[IMNative alloc] initWithPlacementId: placementId delegate: self.nativeAdDelegate];
self.nativeAd.extras = [self extrasForParameters: parameters];

// Update GDPR states
[IMSdk setPartnerGDPRConsent: [self consentDictionaryForParameters: parameters]];

NSString *bidResponse = parameters.bidResponse;
if ( [bidResponse al_isValidString] )
{
[self.nativeAd load: [bidResponse dataUsingEncoding: NSUTF8StringEncoding]];
}
else
{
[self.nativeAd load];
}
}

#pragma mark - Helper Methods

- (IMInterstitial *)loadFullscreenAdForPlacementId:(long long)placementId
Expand Down Expand Up @@ -672,3 +737,183 @@ - (void)interstitial:(IMInterstitial *)interstitial rewardActionCompletedWithRew
}

@end

@implementation ALInMobiMediationAdapterNativeAdDelegate

- (instancetype)initWithParentAdapter:(ALInMobiMediationAdapter *)parentAdapter
parameters:(id<MAAdapterResponseParameters>)parameters
andNotify:(id<MANativeAdAdapterDelegate>)delegate
{
self = [super init];
if ( self )
{
self.parentAdapter = parentAdapter;
self.serverParameters = parameters.serverParameters;
self.delegate = delegate;
self.placementId = parameters.thirdPartyAdPlacementIdentifier;
}
return self;
}

- (void)nativeDidFinishLoading:(IMNative *)nativeAd
{
if ( !nativeAd )
{
[self.parentAdapter log: @"Native ad failed to load: no fill"];
[self.delegate didFailToLoadNativeAdWithError: MAAdapterError.noFill];

return;
}

NSString *templateName = [self.serverParameters al_stringForKey: @"template" defaultValue: @""];
BOOL isTemplateAd = [templateName al_isValidString];
if ( ![self hasRequiredAssetsInAd: nativeAd isTemplateAd: isTemplateAd] )
{
[self.parentAdapter e: @"Native ad (%@) does not have required assets.", nativeAd];
[self.delegate didFailToLoadNativeAdWithError: [MAAdapterError errorWithCode: -5400 errorString: @"Missing Native Ad Assets"]];

return;
}

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

dispatchOnMainQueue(^{

MANativeAd *maxNativeAd = [[MAInMobiNativeAd alloc] initWithParentAdapter: self.parentAdapter
andNotify: self.delegate
builderBlock:^(MANativeAdBuilder *builder) {
builder.title = nativeAd.adTitle;
builder.body = nativeAd.description;
builder.callToAction = nativeAd.adCtaText;
builder.icon = [[MANativeAdImage alloc] initWithImage: nativeAd.adIcon];
builder.mediaView = [nativeAd primaryViewOfWidth: CGRectGetWidth([UIApplication sharedApplication].keyWindow.bounds)];
}];

NSDictionary *extraInfo = [nativeAd.creativeId al_isValidString] ? @{@"creative_id" : nativeAd.creativeId} : nil;
[self.delegate didLoadAdForNativeAd: maxNativeAd withExtraInfo: extraInfo];
});
}

- (void)native:(IMNative *)native didFailToLoadWithError:(IMRequestStatus *)error
{
[self.parentAdapter log: @"Native ad failed to load with error: %@", error];

MAAdapterError *adapterError = [ALInMobiMediationAdapter toMaxError: error];
[self.delegate didFailToLoadNativeAdWithError: adapterError];
}

- (void)nativeWillPresentScreen:(IMNative *)native
{
[self.parentAdapter log: @"Native ad will present"];
}

- (void)nativeDidPresentScreen:(IMNative *)native
{
[self.parentAdapter log: @"Native ad did present"];
}

- (void)nativeWillDismissScreen:(IMNative *)native
{
[self.parentAdapter log: @"Native ad will dismiss the screen"];
}

- (void)nativeDidDismissScreen:(IMNative *)native
{
[self.parentAdapter log: @"Native ad did dismiss the screen"];
}

- (void)userWillLeaveApplicationFromNative:(IMNative *)native
{
[self.parentAdapter log: @"Native ad will leave the application"];
}

- (void)nativeAdImpressed:(IMNative *)native
{
[self.parentAdapter log: @"Native ad did show"];
[self.delegate didDisplayNativeAdWithExtraInfo: nil];
}

- (void)native:(IMNative *)native didInteractWithParams:(NSDictionary *)params
{
[self.parentAdapter log: @"Native ad clicked"];
[self.delegate didClickNativeAd];
}

- (void)nativeDidFinishPlayingMedia:(IMNative *)native
{
[self.parentAdapter log: @"Native ad did finish playing media"];
}

- (void)userDidSkipPlayingMediaFromNative:(IMNative *)native
{
[self.parentAdapter log: @"Native ad user skipped media"];
}

- (void)native:(IMNative *)native adAudioStateChanged:(BOOL)audioStateMuted
{
[self.parentAdapter log: @"Native ad audio state changed"];
}

- (BOOL)hasRequiredAssetsInAd:(IMNative *)nativeAd isTemplateAd:(BOOL)isTemplateAd
{
if ( isTemplateAd )
{
return [nativeAd.adTitle al_isValidString];
}
else
{
return [nativeAd.adTitle al_isValidString]
&& [nativeAd.adCtaText al_isValidString];
}
}

@end

@implementation MAInMobiNativeAd

- (instancetype)initWithParentAdapter:(ALInMobiMediationAdapter *)parentAdapter
andNotify:(id<MANativeAdAdapterDelegate>)delegate
builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock
{
self = [super initWithFormat: MAAdFormat.native builderBlock: builderBlock];
if ( self )
{
self.parentAdapter = parentAdapter;
self.delegate = delegate;
}
return self;
}

- (void)prepareViewForInteraction:(MANativeAdView *)maxNativeAdView
{
if ( !self.parentAdapter.nativeAd )
{
[self.parentAdapter e: @"Failed to register native ad views: native ad is nil."];
return;
}

// InMobi is not providing a method to bind views with landing url, so we need to do it manually
dispatchOnMainQueue(^{
self.parentAdapter.titleGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickNativeView)];
self.parentAdapter.advertiserGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickNativeView)];
self.parentAdapter.bodyGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickNativeView)];
self.parentAdapter.iconGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickNativeView)];
self.parentAdapter.ctaGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickNativeView)];

[maxNativeAdView.titleLabel addGestureRecognizer: self.parentAdapter.titleGestureRecognizer];
[maxNativeAdView.advertiserLabel addGestureRecognizer: self.parentAdapter.advertiserGestureRecognizer];
[maxNativeAdView.bodyLabel addGestureRecognizer: self.parentAdapter.bodyGestureRecognizer];
[maxNativeAdView.iconImageView addGestureRecognizer: self.parentAdapter.iconGestureRecognizer];
[maxNativeAdView.callToActionButton addGestureRecognizer: self.parentAdapter.ctaGestureRecognizer];
});
}

- (void)clickNativeView
{
[self.parentAdapter log: @"Native ad clicked from gesture recognizer"];

[self.parentAdapter.nativeAd reportAdClickAndOpenLandingPage];
[self.delegate didClickNativeAd];
}

@end

0 comments on commit 2f4fe77

Please sign in to comment.