From aca2a74dd82641c6da3737d1cbd42ce8ccd0c110 Mon Sep 17 00:00:00 2001 From: Vincent Guerci Date: Mon, 20 Jul 2020 12:01:41 +0200 Subject: [PATCH] Mopub SDK v5.13 support --- CHANGELOG.md | 6 ++ CRBannerCustomEvent.h | 7 +-- CRBannerCustomEvent.m | 35 ++++++----- CRCriteoAdapterConfiguration.m | 4 +- CRInterstitialCustomEvent.h | 11 +--- CRInterstitialCustomEvent.m | 106 +++++++++++++++++++-------------- 6 files changed, 91 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1855efc..115ea4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CRBannerCustomEvent.h b/CRBannerCustomEvent.h index e94ee90..9eb01f1 100644 --- a/CRBannerCustomEvent.h +++ b/CRBannerCustomEvent.h @@ -22,7 +22,7 @@ #import #else #import "MoPub.h" -#import "MPBannerCustomEvent.h" +#import "MPInlineAdAdapter.h" #endif #import @@ -31,10 +31,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface CRBannerCustomEvent : MPBannerCustomEvent - -- (instancetype) init; - +@interface CRBannerCustomEvent : MPInlineAdAdapter @end NS_ASSUME_NONNULL_END diff --git a/CRBannerCustomEvent.m b/CRBannerCustomEvent.m index ec56a9b..c97a1fd 100644 --- a/CRBannerCustomEvent.m +++ b/CRBannerCustomEvent.m @@ -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; @@ -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]; } } diff --git a/CRCriteoAdapterConfiguration.m b/CRCriteoAdapterConfiguration.m index 933083a..e23d93b 100644 --- a/CRCriteoAdapterConfiguration.m +++ b/CRCriteoAdapterConfiguration.m @@ -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 { @@ -36,7 +36,7 @@ - (NSString *)moPubNetworkName{ } - (NSString *)networkSdkVersion { - return @"3.7.0.0"; + return @"3.8.0.0"; } - (void)initializeNetworkWithConfiguration:(NSDictionary *)configuration complete:(void(^)(NSError *))complete { diff --git a/CRInterstitialCustomEvent.h b/CRInterstitialCustomEvent.h index e35fa8a..2be58a7 100644 --- a/CRInterstitialCustomEvent.h +++ b/CRInterstitialCustomEvent.h @@ -22,7 +22,7 @@ #import #else #import "MoPub.h" -#import "MPInterstitialCustomEvent.h" +#import "MPFullscreenAdAdapter.h" #endif #import @@ -30,14 +30,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface CRInterstitialCustomEvent : MPInterstitialCustomEvent - -- (instancetype) init; - -- (void) requestInterstitialWithCustomEventInfo:(NSDictionary *)info; - -- (void) showInterstitialFromRootViewController:(UIViewController *)rootViewController; - +@interface CRInterstitialCustomEvent : MPFullscreenAdAdapter @end NS_ASSUME_NONNULL_END diff --git a/CRInterstitialCustomEvent.m b/CRInterstitialCustomEvent.m index 2df0861..fb95bb6 100644 --- a/CRInterstitialCustomEvent.m +++ b/CRInterstitialCustomEvent.m @@ -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; } @@ -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; @@ -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]; } }