Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Mopub SDK v5.13 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vguerci committed Jul 20, 2020
1 parent d16bd3b commit aca2a74
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 78 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Note: Adapters are updated to follow Criteo Publisher SDK versions.
i.e. v3.6.1.0 adapters target a SDK with minimum v3.6.1
Unless the adapters themselves are modified, this won't be reflected in this changelog.
--------------------------------------------------------------------------------
## Version 3.8.0.0
- **Features**
- Mopub SDK v5.13 support:
- Has breaking changes that are not backward compatible
- Requires Mopub >= 5.13 and as a consequence iOS 10
--------------------------------------------------------------------------------
## Version 3.4.1.0
- **Features**
- Update the Criteo Publisher SDK with the Mopub's consent
Expand Down
7 changes: 2 additions & 5 deletions CRBannerCustomEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#import <MoPubSDKFramework/MoPub.h>
#else
#import "MoPub.h"
#import "MPBannerCustomEvent.h"
#import "MPInlineAdAdapter.h"
#endif

#import <Foundation/Foundation.h>
Expand All @@ -31,10 +31,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface CRBannerCustomEvent : MPBannerCustomEvent <CRBannerViewDelegate>

- (instancetype) init;

@interface CRBannerCustomEvent : MPInlineAdAdapter <CRBannerViewDelegate, MPThirdPartyInlineAdAdapter>
@end

NS_ASSUME_NONNULL_END
35 changes: 19 additions & 16 deletions CRBannerCustomEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,28 @@
// Private properties
@interface CRBannerCustomEvent()

@property (nonatomic, strong) CRBannerView *bannerView;
@property(nonatomic, strong) CRBannerView *bannerView;

@end

@implementation CRBannerCustomEvent

@synthesize delegate;
@synthesize localExtras;

- (instancetype) init {
self = [super init];
return self;
}

- (void) requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info {
[self requestAdWithSize:size customEventInfo:info adMarkup:nil];
}

- (void) requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info adMarkup:(NSString *)adMarkup {
- (void)requestAdWithSize:(CGSize)size adapterInfo:(NSDictionary *)info adMarkup:(NSString *)adMarkup {
if (![CRCustomEventHelper checkValidInfo:info]) {
if ([self.delegate respondsToSelector:@selector(bannerCustomEvent:didFailToLoadAdWithError:)]) {
if ([self.delegate respondsToSelector:@selector(inlineAdAdapter:didFailToLoadAdWithError:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *errorDescription = [NSString stringWithFormat:@"Criteo Banner ad request failed due to invalid server parameters."];
[self.delegate bannerCustomEvent:self didFailToLoadAdWithError:[NSError errorWithCode:MOPUBErrorServerError localizedDescription:errorDescription]];
NSString *errorDescription = @"Criteo Banner ad request failed due to invalid server parameters.";
NSError *error = [NSError errorWithCode:MOPUBErrorServerError
localizedDescription:errorDescription];
[self.delegate inlineAdAdapter:self didFailToLoadAdWithError:error];
});
}
return;
Expand All @@ -61,24 +62,26 @@ - (void) requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info adM
}

# pragma mark - CRBannerViewDelegate methods
- (void) bannerDidReceiveAd:(CRBannerView *)bannerView {
if ([self.delegate respondsToSelector:@selector(bannerCustomEvent:didLoadAd:)]){
[self.delegate bannerCustomEvent:self didLoadAd:self.bannerView];

- (void)bannerDidReceiveAd:(CRBannerView *)bannerView {
if ([self.delegate respondsToSelector:@selector(inlineAdAdapter:didLoadAdWithAdView:)]) {
[self.delegate inlineAdAdapter:self didLoadAdWithAdView:self.bannerView];
}
}

- (void) banner:(CRBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
if ([self.delegate respondsToSelector:@selector(bannerCustomEvent:didFailToLoadAdWithError:)]) {
if ([self.delegate respondsToSelector:@selector(inlineAdAdapter:didFailToLoadAdWithError:)]) {
NSString *errorDescription = [NSString stringWithFormat:@"Criteo Banner failed to load with error: %@", error.localizedDescription];
NSError *mopubError = [NSError errorWithCode:MOPUBErrorAdapterFailedToLoadAd localizedDescription:errorDescription];
[self.delegate bannerCustomEvent:self didFailToLoadAdWithError:mopubError];
[self.delegate inlineAdAdapter:self didFailToLoadAdWithError:mopubError];
}
}

# pragma mark - optional delegate invocations

- (void) bannerWillLeaveApplication:(CRBannerView *)bannerView {
if ([self.delegate respondsToSelector:@selector(bannerCustomEventWillLeaveApplication:)]) {
[self.delegate bannerCustomEventWillLeaveApplication:self];
if ([self.delegate respondsToSelector:@selector(inlineAdAdapterWillLeaveApplication:)]) {
[self.delegate inlineAdAdapterWillLeaveApplication:self];
}
}

Expand Down
4 changes: 2 additions & 2 deletions CRCriteoAdapterConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (NSString *)adapterVersion {
// We use an hardcoded value (not a macro) so
// that the file is self-contained in the
// open-source repository.
return @"3.7.0.0";
return @"3.8.0.0";
}

- (NSString *)biddingToken {
Expand All @@ -36,7 +36,7 @@ - (NSString *)moPubNetworkName{
}

- (NSString *)networkSdkVersion {
return @"3.7.0.0";
return @"3.8.0.0";
}

- (void)initializeNetworkWithConfiguration:(NSDictionary<NSString *, id> *)configuration complete:(void(^)(NSError *))complete {
Expand Down
11 changes: 2 additions & 9 deletions CRInterstitialCustomEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@
#import <MoPubSDKFramework/MoPub.h>
#else
#import "MoPub.h"
#import "MPInterstitialCustomEvent.h"
#import "MPFullscreenAdAdapter.h"
#endif

#import <Foundation/Foundation.h>
@import CriteoPublisherSdk;

NS_ASSUME_NONNULL_BEGIN

@interface CRInterstitialCustomEvent : MPInterstitialCustomEvent <CRInterstitialDelegate>

- (instancetype) init;

- (void) requestInterstitialWithCustomEventInfo:(NSDictionary *)info;

- (void) showInterstitialFromRootViewController:(UIViewController *)rootViewController;

@interface CRInterstitialCustomEvent : MPFullscreenAdAdapter <CRInterstitialDelegate, MPThirdPartyFullscreenAdAdapter>
@end

NS_ASSUME_NONNULL_END
106 changes: 60 additions & 46 deletions CRInterstitialCustomEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
#import "CRCustomEventHelper.h"
#import "NSString+MPConsentStatus.h"

// Private property
@interface CRInterstitialCustomEvent ()

@property (nonatomic, strong) CRInterstitial *interstitial;
@property(nonatomic, strong) CRInterstitial *interstitial;

@end

@implementation CRInterstitialCustomEvent

- (instancetype) init {
@synthesize delegate;
@synthesize localExtras;

- (instancetype)init {
self = [super init];
return self;
}
Expand All @@ -39,17 +41,13 @@ - (void) dealloc {
self.interstitial.delegate = nil;
}

- (void) requestInterstitialWithCustomEventInfo:(NSDictionary *)info {
[self requestInterstitialWithCustomEventInfo:info adMarkup:nil];
}

- (void) requestInterstitialWithCustomEventInfo:(NSDictionary *)info adMarkup:(NSString *)adMarkup {
- (void)requestAdWithAdapterInfo:(NSDictionary *)info adMarkup:(NSString *)adMarkup {
if(![CRCustomEventHelper checkValidInfo:info]) {
if([self.delegate respondsToSelector:@selector(interstitialCustomEvent:didFailToLoadAdWithError:)]) {
if([self.delegate respondsToSelector:@selector(fullscreenAdAdapter:didFailToLoadAdWithError:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate interstitialCustomEvent:self
didFailToLoadAdWithError:[NSError errorWithCode:MOPUBErrorServerError
localizedDescription:@"Criteo Interstitial ad request failed due to invalid server parameters."]];
[self.delegate fullscreenAdAdapter:self
didFailToLoadAdWithError:[NSError errorWithCode:MOPUBErrorServerError
localizedDescription:@"Criteo Interstitial ad request failed due to invalid server parameters."]];
});
}
return;
Expand All @@ -66,75 +64,91 @@ - (void) requestInterstitialWithCustomEventInfo:(NSDictionary *)info adMarkup:(N
[self.interstitial loadAd];
}

- (void) showInterstitialFromRootViewController:(UIViewController *)rootViewController {
[self.interstitial presentFromRootViewController:rootViewController];
# pragma mark - MoPub required overrides

- (BOOL)enableAutomaticImpressionAndClickTracking {
return YES;
}

- (BOOL)isRewardExpected {
return NO;
}

- (void)setHasAdAvailable:(BOOL)hasAdAvailable {}

- (BOOL)hasAdAvailable {
return self.interstitial.isAdLoaded;
}

- (void)presentAdFromViewController:(UIViewController *)viewController {
[self.interstitial presentFromRootViewController:viewController];
}

# pragma mark - MoPub required delegate methods

// These callbacks are called on the main thread from the Criteo SDK
- (void) interstitialDidReceiveAd:(CRInterstitial *)interstitial {
// Signals that Criteo is willing to display an ad
// Intentionally left blank
}

- (void) interstitial:(CRInterstitial *)interstitial didFailToReceiveAdWithError:(NSError *)error {
if([self.delegate respondsToSelector:@selector(interstitialCustomEvent:didFailToLoadAdWithError:)]) {
NSString *failure = [NSString stringWithFormat:@"Criteo Interstitial failed to load with error : %@"
, error.localizedDescription];
- (void)interstitial:(CRInterstitial *)interstitial didFailToReceiveAdWithError:(NSError *)error {
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapter:didFailToLoadAdWithError:)]) {
NSString *failure = [NSString stringWithFormat:@"Criteo Interstitial failed to load with error : %@",
error.localizedDescription];
NSError *finalError = [NSError errorWithCode:MOPUBErrorAdapterFailedToLoadAd localizedDescription:failure];
[self.delegate interstitialCustomEvent:self
didFailToLoadAdWithError:finalError];
[self.delegate fullscreenAdAdapter:self didFailToLoadAdWithError:finalError];
}
}

- (void) interstitialWillAppear:(CRInterstitial *)interstitial {
if([self.delegate respondsToSelector:@selector(interstitialCustomEventWillAppear:)]) {
[self.delegate interstitialCustomEventWillAppear:self];
- (void)interstitialWillAppear:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapterAdWillAppear:)]) {
[self.delegate fullscreenAdAdapterAdWillAppear:self];
}
}

- (void) interstitialDidAppear:(CRInterstitial *)interstitial {
if([self.delegate respondsToSelector:@selector(interstitialCustomEventDidAppear:)]) {
[self.delegate interstitialCustomEventDidAppear:self];
- (void)interstitialDidAppear:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapterAdDidAppear:)]) {
[self.delegate fullscreenAdAdapterAdDidAppear:self];
}
}

- (void) interstitialWillDisappear:(CRInterstitial *)interstitial {
if([self.delegate respondsToSelector:@selector(interstitialCustomEventWillDisappear:)]) {
[self.delegate interstitialCustomEventWillDisappear:self];
- (void)interstitialWillDisappear:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapterAdWillDisappear:)]) {
[self.delegate fullscreenAdAdapterAdWillDisappear:self];
}
}

- (void) interstitialDidDisappear:(CRInterstitial *)interstitial {
if([self.delegate respondsToSelector:(@selector(interstitialCustomEventDidDisappear:))]) {
[self.delegate interstitialCustomEventDidDisappear:self];
- (void)interstitialDidDisappear:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:(@selector(fullscreenAdAdapterAdDidDisappear:))]) {
[self.delegate fullscreenAdAdapterAdDidDisappear:self];
}
}

- (void) interstitialIsReadyToPresent:(CRInterstitial *)interstitial {
if([self.delegate respondsToSelector:@selector(interstitialCustomEvent:didLoadAd:)]) {
[self.delegate interstitialCustomEvent:self didLoadAd:interstitial];
- (void)interstitialIsReadyToPresent:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapterDidLoadAd:)]) {
[self.delegate fullscreenAdAdapterDidLoadAd:self];
}
}

- (void) interstitial:(CRInterstitial *)interstitial didFailToReceiveAdContentWithError:(NSError *)error {
- (void)interstitial:(CRInterstitial *)interstitial didFailToReceiveAdContentWithError:(NSError *)error {
// Signals that there was an error when Criteo was attempting to fetch the ad content
if([self.delegate respondsToSelector:@selector(interstitialCustomEvent:didFailToLoadAdWithError:)]) {
NSString *failure = [NSString stringWithFormat:@"Criteo Interstitial failed to load ad content with error : %@"
, error.localizedDescription];
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapter:didFailToLoadAdWithError:)]) {
NSString *failure = [NSString stringWithFormat:@"Criteo Interstitial failed to load ad content with error : %@",
error.localizedDescription];
NSError *finalError = [NSError errorWithCode:MOPUBErrorAdapterFailedToLoadAd localizedDescription:failure];
[self.delegate interstitialCustomEvent:self
didFailToLoadAdWithError:finalError];
[self.delegate fullscreenAdAdapter:self didFailToLoadAdWithError:finalError];
}
}

# pragma mark - MoPub delegate to track clicks
- (void) interstitialWillLeaveApplication:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:@selector(interstitialCustomEventWillLeaveApplication:)]) {
[self.delegate interstitialCustomEventWillLeaveApplication:self];

- (void)interstitialWillLeaveApplication:(CRInterstitial *)interstitial {
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapterWillLeaveApplication:)]) {
[self.delegate fullscreenAdAdapterWillLeaveApplication:self];
}
if([self.delegate respondsToSelector:@selector(interstitialCustomEventDidReceiveTapEvent:)]) {
[self.delegate interstitialCustomEventDidReceiveTapEvent:self];
if ([self.delegate respondsToSelector:@selector(fullscreenAdAdapterDidReceiveTap:)]) {
[self.delegate fullscreenAdAdapterDidReceiveTap:self];
}
}

Expand Down

0 comments on commit aca2a74

Please sign in to comment.