diff --git a/Vungle/AppLovinMediationVungleAdapter.podspec b/Vungle/AppLovinMediationVungleAdapter.podspec index 601d10f16e..fe0d8443d2 100644 --- a/Vungle/AppLovinMediationVungleAdapter.podspec +++ b/Vungle/AppLovinMediationVungleAdapter.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.authors = 'AppLovin Corporation' s.name = 'AppLovinMediationVungleAdapter' -s.version = '6.12.3.0' +s.version = '7.0.1.0' s.platform = :ios, '10.0' s.summary = 'Vungle adapter used for mediation with the AppLovin MAX SDK' s.homepage = "https://github.com/CocoaPods/Specs/search?o=desc&q=#{s.name}&s=indexed" @@ -26,16 +26,9 @@ s.source = s.vendored_frameworks = "#{s.name}-#{s.version}/#{s.name}.xcframework" -s.dependency 'VungleSDK-iOS', '= 6.12.3' +s.dependency 'VungleAds', '= 7.0.1' s.dependency 'AppLovinSDK' - -s.pod_target_xcconfig = -{ - 'VALID_ARCHS' => 'arm64 arm64e armv7 armv7s x86_64', - 'VALID_ARCHS[sdk=iphoneos*]' => 'arm64 arm64e armv7 armv7s', - 'VALID_ARCHS[sdk=iphonesimulator*]' => 'arm64 arm64e x86_64', - 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' -} +s.swift_version = '5.0' s.description = <<-DESC diff --git a/Vungle/CHANGELOG.md b/Vungle/CHANGELOG.md index cfeb914528..cb798adecd 100644 --- a/Vungle/CHANGELOG.md +++ b/Vungle/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 7.0.1.0 +* Certified with Vungle SDK 7.0.1. +* Update to use instance based APIs. +* Updated minimum Xcode requirement to 14.1. +* Remove the `privacySettingForSelector:fromParameters:` function and call privacy methods directly. +* Now requires MAX SDK version 6.14.0 or higher.  +* Fixed potential memory leaks by clearing delegates in `destroy:` method. + ## 6.12.3.0 * Certified with Vungle SDK 6.12.3. diff --git a/Vungle/VungleAdapter.xcodeproj/project.pbxproj b/Vungle/VungleAdapter.xcodeproj/project.pbxproj index 5136f17ab7..2728691fa7 100644 --- a/Vungle/VungleAdapter.xcodeproj/project.pbxproj +++ b/Vungle/VungleAdapter.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 6A561CE0219BB5A600E3749A /* AppLovinSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D31B64D219BA4E600875D92 /* AppLovinSDK.framework */; }; 6A9A772A21A4F43A00151D7A /* ALVungleMediationAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A9A772821A4F43A00151D7A /* ALVungleMediationAdapter.m */; }; + E4F5B3D58D41BEC48ED8620F /* Pods_VungleAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A0100E7A4EC559BA0B698A2 /* Pods_VungleAdapter.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -25,6 +26,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 18566C026FA582A3AA2D6C83 /* Pods-VungleAdapter.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VungleAdapter.debug.xcconfig"; path = "Target Support Files/Pods-VungleAdapter/Pods-VungleAdapter.debug.xcconfig"; sourceTree = ""; }; 1D31B64D219BA4E600875D92 /* AppLovinSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AppLovinSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1D9AE8E221423C7D00080475 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 1D9AE8E321423C7D00080475 /* SafariServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SafariServices.framework; path = System/Library/Frameworks/SafariServices.framework; sourceTree = SDKROOT; }; @@ -40,11 +42,13 @@ 1D9AE8ED21423C7E00080475 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 1D9AE8EE21423C7E00080475 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 1D9AE8FC21423C9200080475 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 2A0100E7A4EC559BA0B698A2 /* Pods_VungleAdapter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_VungleAdapter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6A561CE5219BB5A600E3749A /* libVungleAdapter.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libVungleAdapter.a; sourceTree = BUILT_PRODUCTS_DIR; }; 6A5A633A21C0875E00B755D7 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; }; 6A5A633B21C0875E00B755D7 /* AppLovinMediationVungleAdapter.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = AppLovinMediationVungleAdapter.podspec; sourceTree = ""; }; 6A9A772821A4F43A00151D7A /* ALVungleMediationAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ALVungleMediationAdapter.m; sourceTree = ""; }; 6A9A772921A4F43A00151D7A /* ALVungleMediationAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALVungleMediationAdapter.h; sourceTree = ""; }; + DE32188EF62ECA108FB916FB /* Pods-VungleAdapter.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VungleAdapter.release.xcconfig"; path = "Target Support Files/Pods-VungleAdapter/Pods-VungleAdapter.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -53,6 +57,7 @@ buildActionMask = 2147483647; files = ( 6A561CE0219BB5A600E3749A /* AppLovinSDK.framework in Frameworks */, + E4F5B3D58D41BEC48ED8620F /* Pods_VungleAdapter.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -77,6 +82,7 @@ 1D9AE8EA21423C7E00080475 /* SystemConfiguration.framework */, 1D9AE8E821423C7E00080475 /* UIKit.framework */, 1D9AE8E721423C7E00080475 /* WebKit.framework */, + 2A0100E7A4EC559BA0B698A2 /* Pods_VungleAdapter.framework */, ); name = Frameworks; sourceTree = ""; @@ -88,6 +94,7 @@ 6A5A632921C086CF00B755D7 /* Supporting Files */, 1D97FB861FBCF38B00D6C309 /* Products */, 1D2303A61FBCF4C7001939D7 /* Frameworks */, + 2B2BE71AB9E6CCE4ACA5EC84 /* Pods */, ); sourceTree = ""; }; @@ -99,6 +106,16 @@ name = Products; sourceTree = ""; }; + 2B2BE71AB9E6CCE4ACA5EC84 /* Pods */ = { + isa = PBXGroup; + children = ( + 18566C026FA582A3AA2D6C83 /* Pods-VungleAdapter.debug.xcconfig */, + DE32188EF62ECA108FB916FB /* Pods-VungleAdapter.release.xcconfig */, + ); + name = Pods; + path = "../../iOS-Workspace/Pods"; + sourceTree = ""; + }; 6A5A632921C086CF00B755D7 /* Supporting Files */ = { isa = PBXGroup; children = ( @@ -124,6 +141,7 @@ isa = PBXNativeTarget; buildConfigurationList = 6A561CE2219BB5A600E3749A /* Build configuration list for PBXNativeTarget "VungleAdapter" */; buildPhases = ( + C3189E071ED01B7D7F11401C /* [CP] Check Pods Manifest.lock */, 6A561CDD219BB5A600E3749A /* Sources */, 6A561CDF219BB5A600E3749A /* Frameworks */, 6A561CE1219BB5A600E3749A /* Copy Files */, @@ -169,6 +187,31 @@ }; /* End PBXProject section */ +/* Begin PBXShellScriptBuildPhase section */ + C3189E071ED01B7D7F11401C /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-VungleAdapter-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 6A561CDD219BB5A600E3749A /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -219,7 +262,6 @@ ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = ""; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -235,11 +277,9 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LIBRARY_SEARCH_PATHS = ""; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; - VALID_ARCHS = "$(ARCHS_STANDARD)"; }; name = Debug; }; @@ -281,7 +321,6 @@ ENABLE_BITCODE = NO; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - FRAMEWORK_SEARCH_PATHS = ""; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -291,55 +330,45 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LIBRARY_SEARCH_PATHS = ""; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; - VALID_ARCHS = "$(ARCHS_STANDARD)"; }; name = Release; }; 6A561CE3219BB5A600E3749A /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 18566C026FA582A3AA2D6C83 /* Pods-VungleAdapter.debug.xcconfig */; buildSettings = { BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CODE_SIGN_STYLE = Manual; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = X8JXXK4FF5; ENABLE_BITCODE = NO; - EXCLUDED_ARCHS = i386; - FRAMEWORK_SEARCH_PATHS = "../../iOS-Workspace/Pods/**"; - HEADER_SEARCH_PATHS = ""; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LIBRARY_SEARCH_PATHS = "$(inherited)"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SYSTEM_FRAMEWORK_SEARCH_PATHS = ""; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; 6A561CE4219BB5A600E3749A /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = DE32188EF62ECA108FB916FB /* Pods-VungleAdapter.release.xcconfig */; buildSettings = { BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CODE_SIGN_STYLE = Manual; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = X8JXXK4FF5; ENABLE_BITCODE = NO; - EXCLUDED_ARCHS = i386; - FRAMEWORK_SEARCH_PATHS = "../../iOS-Workspace/Pods/**"; - HEADER_SEARCH_PATHS = ""; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - LIBRARY_SEARCH_PATHS = "$(inherited)"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SYSTEM_FRAMEWORK_SEARCH_PATHS = ""; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Vungle/VungleAdapter/ALVungleMediationAdapter.m b/Vungle/VungleAdapter/ALVungleMediationAdapter.m index a5ba47eacb..8e84b52499 100644 --- a/Vungle/VungleAdapter/ALVungleMediationAdapter.m +++ b/Vungle/VungleAdapter/ALVungleMediationAdapter.m @@ -7,37 +7,41 @@ // #import "ALVungleMediationAdapter.h" -#import -#import -#import - -#define ADAPTER_VERSION @"6.12.3.0" - -// TODO: Remove when SDK with App Open APIs is released -@protocol MAAppOpenAdapterDelegateTemp -- (void)didLoadAppOpenAd; -- (void)didLoadAppOpenAdWithExtraInfo:(nullable NSDictionary *)extraInfo; -- (void)didFailToLoadAppOpenAdWithError:(MAAdapterError *)adapterError; -- (void)didDisplayAppOpenAd; -- (void)didDisplayAppOpenAdWithExtraInfo:(nullable NSDictionary *)extraInfo; -- (void)didClickAppOpenAd; -- (void)didClickAppOpenAdWithExtraInfo:(nullable NSDictionary *)extraInfo; -- (void)didHideAppOpenAd; -- (void)didHideAppOpenAdWithExtraInfo:(nullable NSDictionary *)extraInfo; -- (void)didFailToDisplayAppOpenAdWithError:(MAAdapterError *)adapterError; +#import + +#define ADAPTER_VERSION @"7.0.1.0" + +@interface ALVungleMediationAdapterInterstitialAdDelegate : NSObject +@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; +@property (nonatomic, strong) id delegate; +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate; @end -@interface ALVungleMediationAdapterRouter : ALMediationAdapterRouter -@property (nonatomic, copy, nullable) void(^oldCompletionHandler)(void); -@property (nonatomic, copy, nullable) void(^completionBlock)(MAAdapterInitializationStatus, NSString *_Nullable); +@interface ALVungleMediationAdapterAppOpenAdDelegate : NSObject +@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; +@property (nonatomic, strong) id delegate; +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate; +@end + +@interface ALVungleMediationAdapterRewardedAdDelegate : NSObject +@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; +@property (nonatomic, strong) id delegate; @property (nonatomic, assign, getter=hasGrantedReward) BOOL grantedReward; -@property (nonatomic, strong) NSMutableDictionary *creativeIdentifiers; +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate; +@end -- (void)updateUserPrivacySettingsForParameters:(id)parameters; -- (nullable NSNumber *)privacySettingForSelector:(SEL)selector fromParameters:(id)parameters; +@interface ALVungleMediationAdapterAdViewDelegate : NSObject +@property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; +@property (nonatomic, strong) MAAdFormat *adFormat; +@property (nonatomic, strong) id parameters; +@property (nonatomic, strong) id delegate; +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter + format:(MAAdFormat *)adFormat + parameters:(id)parameters + andNotify:(id)delegate; @end -@interface ALVungleMediationAdapterNativeAdViewDelegate : NSObject +@interface ALVungleMediationAdapterNativeAdViewDelegate : NSObject @property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; @property (nonatomic, strong) NSString *placementIdentifier; @property (nonatomic, strong) MAAdFormat *adFormat; @@ -49,7 +53,7 @@ - (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate; @end -@interface ALVungleMediationAdapterNativeAdDelegate : NSObject +@interface ALVungleMediationAdapterNativeAdDelegate : NSObject @property (nonatomic, weak) ALVungleMediationAdapter *parentAdapter; @property (nonatomic, strong) NSString *placementIdentifier; @property (nonatomic, strong) NSDictionary *serverParameters; @@ -66,19 +70,32 @@ - (instancetype)initWithFormat:(MAAdFormat *)format builderBlock:(NS_NOESCAPE MA @end @interface ALVungleMediationAdapter () -@property (nonatomic, strong, readonly) ALVungleMediationAdapterRouter *router; -@property (nonatomic, copy) NSString *placementIdentifier; -@property (nonatomic, strong) UIView *adView; -// Native Ad Properties -@property (nonatomic, strong) VungleNativeAd *nativeAd; +// Interstitial +@property (nonatomic, strong) VungleInterstitial *interstitialAd; +@property (nonatomic, strong) ALVungleMediationAdapterInterstitialAdDelegate *interstitialAdDelegate; + +//App Open Ads +@property (nonatomic, strong) VungleInterstitial *appOpenAd; +@property (nonatomic, strong) ALVungleMediationAdapterAppOpenAdDelegate *appOpenAdDelegate; + +// Rewarded +@property (nonatomic, strong) VungleRewarded *rewardedAd; +@property (nonatomic, strong) ALVungleMediationAdapterRewardedAdDelegate *rewardedAdDelegate; + +// AdView +@property (nonatomic, strong) VungleBanner *adView; +@property (nonatomic, strong) UIView *adViewContainer; +@property (nonatomic, strong) ALVungleMediationAdapterAdViewDelegate *adViewDelegate; + +// Native Ad +@property (nonatomic, strong) VungleNative *nativeAd; @property (nonatomic, strong) ALVungleMediationAdapterNativeAdDelegate *nativeAdDelegate; @property (nonatomic, strong) ALVungleMediationAdapterNativeAdViewDelegate *nativeAdViewDelegate; @end @implementation ALVungleMediationAdapter -@dynamic router; static ALAtomicBoolean *ALVungleInitialized; static MAAdapterInitializationStatus ALVungleIntializationStatus = NSIntegerMin; @@ -94,43 +111,34 @@ + (void)initialize - (void)initializeWithParameters:(id)parameters completionHandler:(void (^)(MAAdapterInitializationStatus, NSString *_Nullable))completionHandler { - [self.router updateUserPrivacySettingsForParameters: parameters]; - - [[VungleSDK sharedSDK] setLoggingEnabled: [parameters isTesting]]; + [self updateUserPrivacySettingsForParameters: parameters]; if ( [ALVungleInitialized compareAndSet: NO update: YES] ) { ALVungleIntializationStatus = MAAdapterInitializationStatusInitializing; - self.router.completionBlock = completionHandler; NSString *appID = [parameters.serverParameters al_stringForKey: @"app_id"]; [self log: @"Initializing Vungle SDK with app id: %@...", appID]; - [VungleSDK sharedSDK].delegate = self.router; - [VungleSDK sharedSDK].creativeTrackingDelegate = self.router; - [VungleSDK sharedSDK].sdkHBDelegate = self.router; - self.router.creativeIdentifiers = [NSMutableDictionary dictionary]; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundeclared-selector" - [[VungleSDK sharedSDK] performSelector: @selector(setPluginName:version:) - withObject: @"max" - withObject: ADAPTER_VERSION]; -#pragma clang diagnostic pop - - NSError *error; - [[VungleSDK sharedSDK] startWithAppId: appID error: &error]; - - if ( error ) - { - [self log: @"Vungle SDK failed to initialize with error: %@", error]; - - ALVungleIntializationStatus = MAAdapterInitializationStatusInitializedFailure; - NSString *errorString = [NSString stringWithFormat: @"%ld:%@", (long) error.code, error.localizedDescription]; - - completionHandler(ALVungleIntializationStatus, errorString); - self.router.completionBlock = nil; - } + [VungleAds setIntegrationName: @"max" version: ADAPTER_VERSION]; + [VungleAds initWithAppId: appID completion:^(NSError * _Nullable error) { + if ( error ) + { + [self log: @"Vungle SDK failed to initialize with error: %@", error]; + + ALVungleIntializationStatus = MAAdapterInitializationStatusInitializedFailure; + NSString *errorString = [NSString stringWithFormat: @"%ld:%@", (long) error.code, error.localizedDescription]; + + completionHandler(ALVungleIntializationStatus, errorString); + } + else + { + [self log: @"Vungle SDK initialized"]; + + ALVungleIntializationStatus = MAAdapterInitializationStatusInitializedSuccess; + completionHandler(ALVungleIntializationStatus, nil); + } + }]; } else { @@ -140,7 +148,7 @@ - (void)initializeWithParameters:(id)paramete - (NSString *)SDKVersion { - return VungleSDKVersion; + return [VungleAds sdkVersion]; } - (NSString *)adapterVersion @@ -150,18 +158,28 @@ - (NSString *)adapterVersion - (void)destroy { - if ( self.adView ) - { - // Note: Not calling this for now because it clears pre-loaded/cached ad view ads as well. - // [[VungleSDK sharedSDK] finishedDisplayingAd]; - self.adView = nil; - } + self.interstitialAd.delegate = nil; + self.interstitialAd = nil; + self.interstitialAdDelegate = nil; + + self.appOpenAd.delegate = nil; + self.appOpenAd = nil; + self.appOpenAdDelegate = nil; - [self.router removeAdapter: self forPlacementIdentifier: self.placementIdentifier]; + self.rewardedAd.delegate = nil; + self.rewardedAd = nil; + self.rewardedAdDelegate = nil; + + self.adView.delegate = nil; + self.adView = nil; + self.adViewDelegate = nil; + self.adViewContainer = nil; [self.nativeAd unregisterView]; self.nativeAd.delegate = nil; self.nativeAd = nil; + self.nativeAdDelegate.delegate = nil; + self.nativeAdViewDelegate.delegate = nil; self.nativeAdDelegate = nil; self.nativeAdViewDelegate = nil; } @@ -172,9 +190,9 @@ - (void)collectSignalWithParameters:(id)parameters { [self log: @"Collecting signal..."]; - [self.router updateUserPrivacySettingsForParameters: parameters]; + [self updateUserPrivacySettingsForParameters: parameters]; - NSString *signal = [[VungleSDK sharedSDK] currentSuperTokenForPlacementID: nil forSize: 0]; + NSString *signal = [VungleAds getBiddingToken]; [delegate didCollectSignal: signal]; } @@ -184,10 +202,10 @@ - (void)loadInterstitialAdForParameters:(id)paramet { NSString *bidResponse = parameters.bidResponse; BOOL isBiddingAd = [bidResponse al_isValidString]; - self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading %@interstitial ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), self.placementIdentifier]; + NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + [self log: @"Loading %@interstitial ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - if ( ![[VungleSDK sharedSDK] isInitialized] ) + if ( ![VungleAds isInitialized] ) { [self log: @"Vungle SDK not successfully initialized: failing interstitial ad load..."]; [delegate didFailToLoadInterstitialAdWithError: MAAdapterError.notInitialized]; @@ -195,21 +213,13 @@ - (void)loadInterstitialAdForParameters:(id)paramet return; } - [self.router addInterstitialAdapter: self - delegate: delegate - forPlacementIdentifier: self.placementIdentifier]; + [self updateUserPrivacySettingsForParameters: parameters]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] ) - { - [self log: @"Interstitial ad loaded"]; - [delegate didLoadInterstitialAd]; - - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] ) + self.interstitialAd = [[VungleInterstitial alloc] initWithPlacementId: placementIdentifier]; + self.interstitialAdDelegate = [[ALVungleMediationAdapterInterstitialAdDelegate alloc] initWithParentAdapter: self andNotify: delegate]; + self.interstitialAd.delegate = self.interstitialAdDelegate; + + if ( [self.interstitialAd canPlayAd] ) { [self log: @"Interstitial ad loaded"]; [delegate didLoadInterstitialAd]; @@ -217,18 +227,7 @@ - (void)loadInterstitialAdForParameters:(id)paramet return; } - NSError *error; - BOOL isLoaded = [self loadAdForParameters: parameters - adFormat: MAAdFormat.interstitial - error: &error]; - - // The `error` parameter may be populated with a return value of `true` - if ( !isLoaded || error ) - { - MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; - [self log: @"Interstitial failed to load with error: %@", adapterError]; - [delegate didFailToLoadInterstitialAdWithError: adapterError]; - } + [self.interstitialAd load: bidResponse]; } - (void)showInterstitialAdForParameters:(id)parameters andNotify:(id)delegate @@ -238,47 +237,37 @@ - (void)showInterstitialAdForParameters:(id)paramet NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; [self log: @"Showing %@interstitial ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - [self.router addShowingAdapter: self]; - - NSError *error; - BOOL willShow = NO; - if ( isBiddingAd ) + if ( [self.interstitialAd canPlayAd] ) { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: placementIdentifier adMarkup: bidResponse] ) + UIViewController *presentingViewController; + if ( ALSdk.versionCode >= 11020199 ) { - willShow = [self showFullscreenAdForParameters: parameters error: &error]; + presentingViewController = parameters.presentingViewController ?: [ALUtils topViewControllerFromKeyWindow]; } + else + { + presentingViewController = [ALUtils topViewControllerFromKeyWindow]; + } + + [self.interstitialAd presentWith: presentingViewController]; } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: placementIdentifier] ) - { - willShow = [self showFullscreenAdForParameters: parameters error: &error]; - } - - if ( !willShow || error ) + else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - MAAdapterError *adapterError = [MAAdapterError errorWithCode: -4205 - errorString: @"Ad Display Failed" - thirdPartySdkErrorCode: error.code - thirdPartySdkErrorMessage: error.localizedDescription]; -#pragma clang diagnostic pop - - [self log: @"Interstitial ad failed to display with error: %@", adapterError]; - [self.router didFailToDisplayAdForPlacementIdentifier: placementIdentifier error: adapterError]; + [self log: @"Failed to show interstitial ad: ad not ready"]; + [delegate didFailToDisplayInterstitialAdWithError: MAAdapterError.adNotReady]; } } #pragma mark - MAAppOpenAdapter Methods -- (void)loadAppOpenAdForParameters:(id)parameters andNotify:(id)delegate +- (void)loadAppOpenAdForParameters:(id)parameters andNotify:(id)delegate { NSString *bidResponse = parameters.bidResponse; BOOL isBiddingAd = [bidResponse al_isValidString]; - self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading %@app open ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), self.placementIdentifier]; + NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + [self log: @"Loading %@app open ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - if ( ![[VungleSDK sharedSDK] isInitialized] ) + if ( ![VungleAds isInitialized] ) { [self log: @"Vungle SDK not successfully initialized: failing app open ad load..."]; [delegate didFailToLoadAppOpenAdWithError: MAAdapterError.notInitialized]; @@ -286,21 +275,13 @@ - (void)loadAppOpenAdForParameters:(id)parameters a return; } - [self.router addAppOpenAdapter: self - delegate: delegate - forPlacementIdentifier: self.placementIdentifier]; + [self updateUserPrivacySettingsForParameters: parameters]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] ) - { - [self log: @"App open ad loaded"]; - [delegate didLoadAppOpenAd]; - - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] ) + self.appOpenAdDelegate = [[ALVungleMediationAdapterAppOpenAdDelegate alloc] initWithParentAdapter: self andNotify: delegate]; + self.appOpenAd = [[VungleInterstitial alloc] initWithPlacementId: placementIdentifier]; + self.appOpenAd.delegate = self.appOpenAdDelegate; + + if ( [self.appOpenAd canPlayAd] ) { [self log: @"App open ad loaded"]; [delegate didLoadAppOpenAd]; @@ -308,55 +289,34 @@ - (void)loadAppOpenAdForParameters:(id)parameters a return; } - NSError *error; - BOOL isLoaded = [self loadAdForParameters: parameters - adFormat: nil // MAAdFormat.appOpen - error: &error]; - - // The `error` parameter may be populated with a return value of `true` - if ( !isLoaded || error ) - { - MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; - [self log: @"App open failed to load with error: %@", adapterError]; - [delegate didFailToDisplayAppOpenAdWithError: adapterError]; - } + [self.appOpenAd load: bidResponse]; } -- (void)showAppOpenAdForParameters:(id)parameters andNotify:(id)delegate +- (void)showAppOpenAdForParameters:(id)parameters andNotify:(id)delegate { NSString *bidResponse = parameters.bidResponse; BOOL isBiddingAd = [bidResponse al_isValidString]; NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; [self log: @"Showing %@app open ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - [self.router addShowingAdapter: self]; - - NSError *error; - BOOL willShow = NO; - if ( isBiddingAd ) + if ( [self.appOpenAd canPlayAd] ) { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: placementIdentifier adMarkup: bidResponse] ) + UIViewController *presentingViewController; + if ( ALSdk.versionCode >= 11020199 ) { - willShow = [self showFullscreenAdForParameters: parameters error: &error]; + presentingViewController = parameters.presentingViewController ?: [ALUtils topViewControllerFromKeyWindow]; } + else + { + presentingViewController = [ALUtils topViewControllerFromKeyWindow]; + } + + [self.appOpenAd presentWith: presentingViewController]; } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: placementIdentifier] ) - { - willShow = [self showFullscreenAdForParameters: parameters error: &error]; - } - - if ( !willShow || error ) + else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - MAAdapterError *adapterError = [MAAdapterError errorWithCode: -4205 - errorString: @"Ad Display Failed" - thirdPartySdkErrorCode: error.code - thirdPartySdkErrorMessage: error.localizedDescription]; -#pragma clang diagnostic pop - - [self log: @"App open ad failed to display with error: %@", adapterError]; - [self.router didFailToDisplayAdForPlacementIdentifier: placementIdentifier error: adapterError]; + [self log: @"Failed to show app open ad: ad not ready"]; + [delegate didFailToDisplayAppOpenAdWithError: MAAdapterError.adNotReady]; } } @@ -366,10 +326,10 @@ - (void)loadRewardedAdForParameters:(id)parameters { NSString *bidResponse = parameters.bidResponse; BOOL isBiddingAd = [bidResponse al_isValidString]; - self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading %@rewarded ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), self.placementIdentifier]; + NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + [self log: @"Loading %@rewarded ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - if ( ![[VungleSDK sharedSDK] isInitialized] ) + if ( ![VungleAds isInitialized] ) { [self log: @"Vungle SDK not successfully initialized: failing rewarded ad load..."]; [delegate didFailToLoadRewardedAdWithError: MAAdapterError.notInitialized]; @@ -377,21 +337,13 @@ - (void)loadRewardedAdForParameters:(id)parameters return; } - [self.router addRewardedAdapter: self - delegate: delegate - forPlacementIdentifier: self.placementIdentifier]; + [self updateUserPrivacySettingsForParameters: parameters]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] ) - { - [self log: @"Rewarded ad loaded"]; - [delegate didLoadRewardedAd]; - - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] ) + self.rewardedAd = [[VungleRewarded alloc] initWithPlacementId: placementIdentifier]; + self.rewardedAdDelegate = [[ALVungleMediationAdapterRewardedAdDelegate alloc] initWithParentAdapter: self andNotify: delegate]; + self.rewardedAd.delegate = self.rewardedAdDelegate; + + if ( [self.rewardedAd canPlayAd] ) { [self log: @"Rewarded ad loaded"]; [delegate didLoadRewardedAd]; @@ -399,18 +351,7 @@ - (void)loadRewardedAdForParameters:(id)parameters return; } - NSError *error; - BOOL isLoaded = [self loadAdForParameters: parameters - adFormat: MAAdFormat.rewarded - error: &error]; - - // The `error` parameter may be populated with a return value of `true` - if ( !isLoaded || error ) - { - MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; - [self log: @"Rewarded failed to load with error: %@", adapterError]; - [delegate didFailToLoadRewardedAdWithError: adapterError]; - } + [self.rewardedAd load: bidResponse]; } - (void)showRewardedAdForParameters:(id)parameters andNotify:(id)delegate @@ -420,36 +361,27 @@ - (void)showRewardedAdForParameters:(id)parameters NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; [self log: @"Showing %@rewarded ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - [self.router addShowingAdapter: self]; - - NSError *error; - BOOL willShow = NO; - if ( isBiddingAd ) + if ( [self.rewardedAd canPlayAd] ) { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: placementIdentifier adMarkup: bidResponse] ) + // Configure reward from server. + [self configureRewardForParameters: parameters]; + + UIViewController *presentingViewController; + if ( ALSdk.versionCode >= 11020199 ) { - [self configureRewardForParameters: parameters]; - willShow = [self showFullscreenAdForParameters: parameters error: &error]; + presentingViewController = parameters.presentingViewController ?: [ALUtils topViewControllerFromKeyWindow]; } + else + { + presentingViewController = [ALUtils topViewControllerFromKeyWindow]; + } + + [self.rewardedAd presentWith: presentingViewController]; } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: placementIdentifier] ) - { - [self configureRewardForParameters: parameters]; - willShow = [self showFullscreenAdForParameters: parameters error: &error]; - } - - if ( !willShow || error ) + else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - MAAdapterError *adapterError = [MAAdapterError errorWithCode: -4205 - errorString: @"Ad Display Failed" - thirdPartySdkErrorCode: error.code - thirdPartySdkErrorMessage: error.localizedDescription]; -#pragma clang diagnostic pop - - [self log: @"Rewarded ad failed to display with error: %@", adapterError]; - [self.router didFailToDisplayAdForPlacementIdentifier: placementIdentifier error: adapterError]; + [self log: @"Failed to show rewarded ad: ad not ready"]; + [delegate didFailToDisplayRewardedAdWithError: MAAdapterError.adNotReady]; } } @@ -459,14 +391,14 @@ - (void)loadAdViewAdForParameters:(id)parameters ad { NSString *bidResponse = parameters.bidResponse; NSString *adFormatLabel = adFormat.label; - self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; BOOL isBiddingAd = [bidResponse al_isValidString]; BOOL isNative = [parameters.serverParameters al_boolForKey: @"is_native"]; - [self log: @"Loading %@%@%@ ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), ( isNative ? @"native " : @"" ), adFormatLabel, self.placementIdentifier]; + [self log: @"Loading %@%@%@ ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), ( isNative ? @"native " : @"" ), adFormatLabel, placementIdentifier]; - if ( ![[VungleSDK sharedSDK] isInitialized] ) + if ( ![VungleAds isInitialized] ) { [self log: @"Vungle SDK not successfully initialized: failing %@ ad load...", adFormatLabel]; [delegate didFailToLoadAdViewAdWithError: MAAdapterError.notInitialized]; @@ -474,6 +406,8 @@ - (void)loadAdViewAdForParameters:(id)parameters ad return; } + [self updateUserPrivacySettingsForParameters: parameters]; + if ( isNative ) { self.nativeAdViewDelegate = [[ALVungleMediationAdapterNativeAdViewDelegate alloc] initWithParentAdapter: self @@ -481,122 +415,23 @@ - (void)loadAdViewAdForParameters:(id)parameters ad parameters: parameters andNotify: delegate]; [self loadVungleNativeAdForParameters: parameters andNotify: self.nativeAdViewDelegate]; - - return; - } - - [self.router addAdViewAdapter: self - delegate: delegate - forPlacementIdentifier: self.placementIdentifier - adView: nil]; - - [[VungleSDK sharedSDK] disableBannerRefresh]; - - VungleAdSize adSize = [ALVungleMediationAdapter vungleBannerAdSizeFromFormat: adFormat]; - if ( isBiddingAd ) - { - if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse] - || [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier adMarkup: bidResponse withSize: adSize] ) - { - [self showAdViewAdForParameters: parameters - adFormat: adFormat - andNotify: delegate]; - return; - } - } - else if ( [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier] - || [[VungleSDK sharedSDK] isAdCachedForPlacementID: self.placementIdentifier withSize: adSize] ) - { - [self showAdViewAdForParameters: parameters - adFormat: adFormat - andNotify: delegate]; - return; - } - - NSError *error; - BOOL isLoaded = [self loadAdForParameters: parameters - adFormat: adFormat - error: &error]; - - if ( !isLoaded || error ) - { - MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; - [self log: @"%@ ad failed to load with error: %@", adFormatLabel, error]; - [delegate didFailToLoadAdViewAdWithError: adapterError]; } else { - [self showAdViewAdForParameters: parameters - adFormat: adFormat - andNotify: delegate]; - } -} - -- (void)showAdViewAdForParameters:(id)parameters adFormat:(MAAdFormat *)adFormat andNotify:(id)delegate -{ - NSString *bidResponse = parameters.bidResponse; - BOOL isBiddingAd = [bidResponse al_isValidString]; - NSString *adFormatLabel = adFormat.label; - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Showing %@%@ ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), adFormatLabel, placementIdentifier]; - - if ( MAAdFormat.banner == adFormat ) - { - self.adView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 50)]; - } - else if ( MAAdFormat.leader == adFormat ) - { - self.adView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 728, 90)]; - } - else if ( MAAdFormat.mrec == adFormat ) - { - self.adView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 300, 250)]; - } - else - { - [NSException raise: NSInvalidArgumentException format: @"Invalid ad format: %@", adFormatLabel]; - } - - [self.router updateAdView: self.adView forPlacementIdentifier: placementIdentifier]; - [self.router addShowingAdapter: self]; - - NSMutableDictionary *adOptions = [self adOptionsForParameters: parameters isFullscreenAd: NO]; - NSError *error; - - // Note: Vungle ad view ads require an additional step to load. A failed [addAdViewToView:] would be considered a failed load. - BOOL willShow; - if ( isBiddingAd ) - { - willShow = [[VungleSDK sharedSDK] addAdViewToView: self.adView - withOptions: adOptions - placementID: placementIdentifier - adMarkup: bidResponse - error: &error]; - } - else - { - willShow = [[VungleSDK sharedSDK] addAdViewToView: self.adView - withOptions: adOptions - placementID: placementIdentifier - error: &error]; - } - - if ( !willShow || error ) - { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - MAAdapterError *adapterError = [MAAdapterError errorWithCode: -4205 - errorString: @"Ad Display Failed" - thirdPartySdkErrorCode: error.code - thirdPartySdkErrorMessage: error.localizedDescription]; -#pragma clang diagnostic pop + BannerSize adSize = [self adSizeFromAdFormat: adFormat]; - [self log: @"%@ ad failed to display with error: %@", adFormatLabel, adapterError]; - [self.router didFailToDisplayAdForPlacementIdentifier: placementIdentifier error: adapterError]; - } - else - { - [delegate didLoadAdForAdView: self.adView]; + self.adView = [[VungleBanner alloc] initWithPlacementId: placementIdentifier size: adSize]; + self.adViewDelegate = [[ALVungleMediationAdapterAdViewDelegate alloc] initWithParentAdapter: self + format: adFormat + parameters: parameters + andNotify: delegate]; + self.adView.delegate = self.adViewDelegate; + + self.adView.enableRefresh = NO; + + self.adViewContainer = [[UIView alloc] initWithFrame: (CGRect) { CGPointZero, adFormat.size }]; + + [self.adView load: bidResponse]; } } @@ -606,9 +441,11 @@ - (void)loadNativeAdForParameters:(id)parameters an { NSString *bidResponse = parameters.bidResponse; BOOL isBiddingAd = [bidResponse al_isValidString]; - self.placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; + + [self log: @"Loading %@native ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), placementIdentifier]; - if ( ![[VungleSDK sharedSDK] isInitialized] ) + if ( ![VungleAds isInitialized] ) { [self log: @"Vungle SDK not successfully initialized: failing native ad load..."]; [delegate didFailToLoadNativeAdWithError: MAAdapterError.notInitialized]; @@ -616,7 +453,7 @@ - (void)loadNativeAdForParameters:(id)parameters an return; } - [self log: @"Loading %@native ad for placement: %@...", ( isBiddingAd ? @"bidding " : @"" ), self.placementIdentifier]; + [self updateUserPrivacySettingsForParameters: parameters]; self.nativeAdDelegate = [[ALVungleMediationAdapterNativeAdDelegate alloc] initWithParentAdapter: self parameters: parameters @@ -626,121 +463,37 @@ - (void)loadNativeAdForParameters:(id)parameters an #pragma mark - Shared Methods -- (BOOL)loadAdForParameters:(id)parameters adFormat:(MAAdFormat *)adFormat error:(NSError **)error +- (void)updateUserPrivacySettingsForParameters:(id)parameters { - [self.router updateUserPrivacySettingsForParameters: parameters]; - - // [loadPlacementWithID:] only supports the withSize parameter for banners and leaders. - // [vungleAdPlayabilityUpdate:] is the callback for the load. - - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - NSString *bidResponse = parameters.bidResponse; - BOOL isBiddingAd = [bidResponse al_isValidString]; - - if ( MAAdFormat.banner == adFormat || MAAdFormat.leader == adFormat ) + NSNumber *hasUserConsent = [parameters hasUserConsent]; + if ( hasUserConsent ) { - VungleAdSize adSize = [ALVungleMediationAdapter vungleBannerAdSizeFromFormat: adFormat]; - if ( isBiddingAd ) - { - return [[VungleSDK sharedSDK] loadPlacementWithID: placementIdentifier - adMarkup: bidResponse - withSize: adSize - error: error]; - } - else - { - return [[VungleSDK sharedSDK] loadPlacementWithID: placementIdentifier - withSize: adSize - error: error]; - } + [VunglePrivacySettings setGDPRStatus: hasUserConsent.boolValue]; + [VunglePrivacySettings setGDPRMessageVersion: @""]; } - else - { - if ( isBiddingAd ) - { - return [[VungleSDK sharedSDK] loadPlacementWithID: placementIdentifier - adMarkup: bidResponse - error: error]; - } - else - { - return [[VungleSDK sharedSDK] loadPlacementWithID: placementIdentifier error: error]; - } - } -} - -- (BOOL)showFullscreenAdForParameters:(id)parameters error:(NSError **)error -{ - NSMutableDictionary *adOptions = [self adOptionsForParameters: parameters isFullscreenAd: YES]; - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - NSString *bidResponse = parameters.bidResponse; - UIViewController *presentingViewController; - if ( ALSdk.versionCode >= 11020199 ) - { - presentingViewController = parameters.presentingViewController ?: [ALUtils topViewControllerFromKeyWindow]; - } - else + NSNumber *isAgeRestrictedUser = [parameters isAgeRestrictedUser]; + if ( isAgeRestrictedUser ) { - presentingViewController = [ALUtils topViewControllerFromKeyWindow]; + [VunglePrivacySettings setCOPPAStatus: isAgeRestrictedUser.boolValue]; } - if ( [bidResponse al_isValidString] ) + NSNumber *isDoNotSell = [parameters isDoNotSell]; + if ( isDoNotSell ) { - return [[VungleSDK sharedSDK] playAd: presentingViewController - options: adOptions - placementID: placementIdentifier - adMarkup: bidResponse - error: error]; - } - else - { - return [[VungleSDK sharedSDK] playAd: presentingViewController - options: adOptions - placementID: placementIdentifier - error: error]; + [VunglePrivacySettings setCCPAStatus: isDoNotSell.boolValue]; } } -- (void)loadVungleNativeAdForParameters:(id)parameters andNotify:(id)delegate +- (void)loadVungleNativeAdForParameters:(id)parameters andNotify:(id)delegate { NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; NSString *bidResponse = parameters.bidResponse; - [self.router updateUserPrivacySettingsForParameters: parameters]; - - self.nativeAd = [[VungleNativeAd alloc] initWithPlacementID: placementIdentifier]; + self.nativeAd = [[VungleNative alloc] initWithPlacementId: placementIdentifier]; self.nativeAd.delegate = delegate; - - if ( [bidResponse al_isValidString] ) - { - [self.nativeAd loadAdWithAdMarkup: bidResponse]; - } - else - { - [self.nativeAd loadAd]; - } -} - -- (NSMutableDictionary *)adOptionsForParameters:(id)parameters isFullscreenAd:(BOOL)isFullscreenAd -{ - NSMutableDictionary *options = [NSMutableDictionary dictionary]; - - // Vungle requested for mute state to only be updated if publisher explicitly muted - if ( [parameters.serverParameters al_boolForKey: @"is_muted"] ) - { - [VungleSDK sharedSDK].muted = YES; - options[VunglePlayAdOptionKeyStartMuted] = @(YES); - } - - // If the app is currently in landscape, lock the ad to landscape. This was an iOS-only bug where Vungle would quickly show an ad in portrait, then - // landscape which is poor UX and caused issues in a pub app. Note that we can't set it for AdView ads as Vungle's SDK will rotate the publisher's app. - if ( isFullscreenAd && ([ALUtils currentOrientationMask] & UIInterfaceOrientationMaskLandscape) ) - { - options[VunglePlayAdOptionKeyOrientations] = @(UIInterfaceOrientationMaskLandscape); - } - - return options; + self.nativeAd.adOptionsPosition = NativeAdOptionsPositionTopRight; + [self.nativeAd load: bidResponse]; } - (NSArray *)clickableViewsForNativeAdView:(MANativeAdView *)maxNativeAdView @@ -783,19 +536,24 @@ - (NSMutableDictionary *)adOptionsForParameters:(id return clickableViews; } -+ (VungleAdSize)vungleBannerAdSizeFromFormat:(MAAdFormat *)adFormat +- (BannerSize)adSizeFromAdFormat:(MAAdFormat *)adFormat { if ( adFormat == MAAdFormat.banner ) { - return VungleAdSizeBanner; + return BannerSizeRegular; } else if ( adFormat == MAAdFormat.leader ) { - return VungleAdSizeBannerLeaderboard; + return BannerSizeLeaderboard; + } + else if ( adFormat == MAAdFormat.mrec ) + { + return BannerSizeMrec; } else { - return VungleAdSizeUnknown; + [NSException raise: NSInvalidArgumentException format: @"Unsupported ad format: %@", adFormat]; + return BannerSizeRegular; } } @@ -803,50 +561,32 @@ + (MAAdapterError *)toMaxError:(nullable NSError *)vungleError { if ( !vungleError ) return MAAdapterError.unspecified; - VungleSDKErrorCode vungleErrorCode = (VungleSDKErrorCode) vungleError.code; + int vungleErrorCode = (int) vungleError.code; MAAdapterError *adapterError = MAAdapterError.unspecified; switch ( vungleErrorCode ) { - case VungleSDKErrorInvalidPlayAdOption: - case VungleSDKErrorInvalidPlayAdExtraKey: - case VungleSDKErrorUnknownPlacementID: - case InvalidPlacementsArray: - case VungleSDKErrorNoAppID: - case VungleSDKErrorIllegalAdRequest: - adapterError = MAAdapterError.invalidConfiguration; - break; - case VungleSDKErrorCannotPlayAd: - case VungleSDKErrorCannotPlayAdAlreadyPlaying: - case VungleSDKErrorInvalidiOSVersion: - case VungleSDKErrorTopMostViewControllerMismatch: - case VungleSDKErrorInvalidAdTypeForNativeAdExperience: - case VungleSDKErrorSetNativeAdLoadCompletionBlock: - case VungleSDKErrorNativeAdLoad: - case VungleSDKErrorMissingAdMarkupForPlacement: - case VungleSDKErrorInvalidAdMarkupForPlacement: - adapterError = MAAdapterError.internalError; - break; - case VungleSDKErrorCannotPlayAdWaiting: - adapterError = MAAdapterError.adNotReady; - break; - case VungleSDKErrorSDKNotInitialized: + case 6: // SDK Not Initialized adapterError = MAAdapterError.notInitialized; break; - case VungleSDKErrorNoAdsAvailable: + case 2: // Invalid AppID + case 201: // Invalid PlacementID + case 500: // BannerView: Invalid Size + adapterError = MAAdapterError.invalidConfiguration; + break; + case 210: // Ad Not Loaded adapterError = MAAdapterError.noFill; break; - case VungleSDKErrorSleepingPlacement: + case 212: // Placement Sleep adapterError = MAAdapterError.invalidLoadState; break; - case VungleSDKErrorInvalidAdTypeForFeedBasedAdExperience: - case VungleSDKErrorFlexFeedContainerViewSizeError: - case VungleSDKErrorFlexFeedContainerViewSizeRatioError: - case VungleSDKErrorNotEnoughFileSystemSize: - case VungleDiscSpaceProviderErrorNoFileSystemAttributes: - case VungleSDKErrorUnknownBannerSize: - case VungleSDKResetPlacementForDifferentAdSize: - case VungleSDKErrorSDKAlreadyInitializing: - adapterError = MAAdapterError.unspecified; + case 304: // Ad Expired + adapterError = MAAdapterError.adExpiredError; + break; + case 303: // Ad Not Ready + adapterError = MAAdapterError.adNotReady; + break; + case 600: // Native Asset Error + adapterError = MAAdapterError.missingRequiredNativeAdAssets; break; } @@ -859,265 +599,363 @@ + (MAAdapterError *)toMaxError:(nullable NSError *)vungleError #pragma clang diagnostic pop } -#pragma mark - Dynamic Properties +@end + +@implementation ALVungleMediationAdapterInterstitialAdDelegate -- (ALVungleMediationAdapterRouter *)router +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate { - return [ALVungleMediationAdapterRouter sharedInstance]; + self = [super init]; + if ( self ) + { + self.parentAdapter = parentAdapter; + self.delegate = delegate; + } + return self; } -@end +- (void)interstitialAdDidLoad:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"Interstitial ad loaded: %@", interstitial.placementId]; + [self.delegate didLoadInterstitialAd]; +} -@implementation ALVungleMediationAdapterRouter +- (void)interstitialAdDidFailToLoad:(VungleInterstitial *)interstitial withError:(NSError *)error +{ + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"Interstitial ad (%@) failed to load with error: %@", interstitial.placementId, adapterError]; + [self.delegate didFailToLoadInterstitialAdWithError: adapterError]; +} -#pragma mark - GDPR +- (void)interstitialAdWillPresent:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"Interstitial ad will present: %@", interstitial.placementId]; +} -- (void)updateUserPrivacySettingsForParameters:(id)parameters +- (void)interstitialAdDidPresent:(VungleInterstitial *)interstitial { - NSNumber *hasUserConsent = [self privacySettingForSelector: @selector(hasUserConsent) fromParameters: parameters]; - if ( hasUserConsent ) - { - VungleConsentStatus contentStatus = hasUserConsent.boolValue ? VungleConsentAccepted : VungleConsentDenied; - [[VungleSDK sharedSDK] updateConsentStatus: contentStatus consentMessageVersion: @""]; - } - - NSNumber *isAgeRestrictedUser = [self privacySettingForSelector: @selector(isAgeRestrictedUser) fromParameters: parameters]; - if ( isAgeRestrictedUser ) - { - [[VungleSDK sharedSDK] updateCOPPAStatus: isAgeRestrictedUser.boolValue]; - } - - if ( ALSdk.versionCode >= 61100 ) - { - NSNumber *isDoNotSell = [self privacySettingForSelector: @selector(isDoNotSell) fromParameters: parameters]; - if ( isDoNotSell ) - { - VungleCCPAStatus ccpaStatus = isDoNotSell.boolValue ? VungleCCPADenied : VungleCCPAAccepted; - [[VungleSDK sharedSDK] updateCCPAStatus: ccpaStatus]; - } - } + [self.parentAdapter log: @"Interstitial ad shown: %@", interstitial.placementId]; } -- (nullable NSNumber *)privacySettingForSelector:(SEL)selector fromParameters:(id)parameters +- (void)interstitialAdDidTrackImpression:(VungleInterstitial *)interstitial { - // Use reflection because compiled adapters have trouble fetching `BOOL` from old SDKs and `NSNumber` from new SDKs (above 6.14.0) - NSMethodSignature *signature = [[parameters class] instanceMethodSignatureForSelector: selector]; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: signature]; - [invocation setSelector: selector]; - [invocation setTarget: parameters]; - [invocation invoke]; + [self.parentAdapter log: @"Interstitial ad impression tracked: %@", interstitial.placementId]; - // Privacy parameters return nullable `NSNumber` on newer SDKs - if ( ALSdk.versionCode >= 6140000 ) + NSString *creativeIdentifier = interstitial.creativeId; + if ( ALSdk.versionCode >= 6150000 && [creativeIdentifier al_isValidString] ) { - NSNumber *__unsafe_unretained value; - [invocation getReturnValue: &value]; - - return value; + [self.delegate didDisplayInterstitialAdWithExtraInfo: @{@"creative_id" : creativeIdentifier}]; } - // Privacy parameters return BOOL on older SDKs else { - BOOL rawValue; - [invocation getReturnValue: &rawValue]; - - return @(rawValue); + [self.delegate didDisplayInterstitialAd]; } } -#pragma mark - VungleSDKDelegate +- (void)interstitialAdDidFailToPresent:(VungleInterstitial *)interstitial withError:(NSError *)error +{ + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"Interstitial ad (%@) failed to show with error: %@", interstitial.placementId, adapterError]; + [self.delegate didFailToDisplayInterstitialAdWithError: adapterError]; +} + +- (void)interstitialAdDidClick:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"Interstitial ad clicked: %@", interstitial.placementId]; + [self.delegate didClickInterstitialAd]; +} + +- (void)interstitialAdWillLeaveApplication:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"Interstitial ad will leave application: %@", interstitial.placementId]; +} + +- (void)interstitialAdWillClose:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"Interstitial ad will close: %@", interstitial.placementId]; +} + +- (void)interstitialAdDidClose:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"Interstitial ad hidden: %@", interstitial.placementId]; + [self.delegate didHideInterstitialAd]; +} + +@end -// This method is called when Vungle's SDK initializes to cache ads; it's also used as the load callback when [loadPlacementWithID:] is called -- (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable placementID:(NSString *)placementID error:(NSError *)error +@implementation ALVungleMediationAdapterAppOpenAdDelegate + +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate { - if ( isAdPlayable ) + self = [super init]; + if ( self ) { - [self log: @"Ad is playable and loaded for placement id: %@", placementID]; - - // NOTE: Break thread context when we call `loadPlacementWithID:` for banners and this calls into SDK downstream without a loadedAdView - deferToNextMainQueueRunloop(^{ - [self didLoadAdForPlacementIdentifier: placementID]; - }); - - return; + self.parentAdapter = parentAdapter; + self.delegate = delegate; } + return self; +} + +- (void)interstitialAdDidLoad:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"App Open ad loaded: %@", interstitial.placementId]; + [self.delegate didLoadAppOpenAd]; +} + +- (void)interstitialAdDidFailToLoad:(VungleInterstitial *)interstitial withError:(NSError *)error +{ + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"App Open ad (%@) failed to load with error: %@", interstitial.placementId, adapterError]; + [self.delegate didFailToLoadAppOpenAdWithError: adapterError]; +} + +- (void)interstitialAdWillPresent:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"App Open will present: %@", interstitial.placementId]; +} + +- (void)interstitialAdDidPresent:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"App Open ad shown: %@", interstitial.placementId]; +} + +- (void)interstitialAdDidTrackImpression:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"App Open ad impression tracked: %@", interstitial.placementId]; - if ( error ) + NSString *creativeIdentifier = interstitial.creativeId; + if ( ALSdk.versionCode >= 6150000 && [creativeIdentifier al_isValidString] ) { - MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; - [self log: @"Ad for placement id %@ failed to load with error: %@", placementID, adapterError]; - [self didFailToLoadAdForPlacementIdentifier: placementID error: adapterError]; + [self.delegate didDisplayAppOpenAdWithExtraInfo: @{@"creative_id" : creativeIdentifier}]; } else { - [self log: @"Ad for placement id %@ received no fill", placementID]; - - // When `isAdPlayable` is `NO` and `error` is `nil` => NO FILL - // https://app.asana.com/0/573104092700345/1161396323081913 - [self didFailToLoadAdForPlacementIdentifier: placementID error: MAAdapterError.noFill]; + [self.delegate didDisplayAppOpenAd]; } } -- (void)vungleWillShowAdForPlacementID:(NSString *)placementID +- (void)interstitialAdDidFailToPresent:(VungleInterstitial *)interstitial withError:(NSError *)error +{ + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"App Open ad (%@) failed to show with error: %@", interstitial.placementId, adapterError]; + [self.delegate didFailToLoadAppOpenAdWithError: adapterError]; +} + +- (void)interstitialAdDidClick:(VungleInterstitial *)interstitial +{ + [self.parentAdapter log: @"App Open ad clicked: %@", interstitial.placementId]; + [self.delegate didClickAppOpenAd]; +} + +- (void)interstitialAdWillLeaveApplication:(VungleInterstitial *)interstitial { - [self log: @"Ad will show"]; + [self.parentAdapter log: @"App Open ad will leave application: %@", interstitial.placementId]; } -- (void)vungleDidShowAdForPlacementID:(NSString *)placementID +- (void)interstitialAdWillClose:(VungleInterstitial *)interstitial { - // Old CIMP location. Caused discrepancies with Vungle. - [self log: @"Ad did show"]; + [self.parentAdapter log: @"App Open ad will close: %@", interstitial.placementId]; } -- (void)vungleAdViewedForPlacement:(NSString *)placementID +- (void)interstitialAdDidClose:(VungleInterstitial *)interstitial { - [self log: @"Ad viewed"]; + [self.parentAdapter log: @"App Open ad hidden: %@", interstitial.placementId]; + [self.delegate didHideAppOpenAd]; +} + +@end + +@implementation ALVungleMediationAdapterRewardedAdDelegate + +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter andNotify:(id)delegate +{ + self = [super init]; + if ( self ) + { + self.parentAdapter = parentAdapter; + self.delegate = delegate; + } + return self; +} + +- (void)rewardedAdDidLoad:(VungleRewarded *)rewarded +{ + [self.parentAdapter log: @"Rewarded ad loaded: %@", rewarded.placementId]; + [self.delegate didLoadRewardedAd]; +} + +- (void)rewardedAdDidFailToLoad:(VungleRewarded *)rewarded withError:(NSError *)error +{ + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"Rewarded ad (%@) failed to load with error: %@", rewarded.placementId, adapterError]; + [self.delegate didFailToLoadRewardedAdWithError: adapterError]; +} + +- (void)rewardedAdWillPresent:(VungleRewarded *)rewarded +{ + [self.parentAdapter log: @"Rewarded ad will present: %@", rewarded.placementId]; +} + +- (void)rewardedAdDidPresent:(VungleRewarded *)rewarded +{ + [self.parentAdapter log: @"Rewarded ad shown: %@", rewarded.placementId]; + [self.delegate didStartRewardedAdVideo]; +} + +- (void)rewardedAdDidTrackImpression:(VungleRewarded *)rewarded +{ + [self.parentAdapter log: @"Rewarded ad impression tracked: %@", rewarded.placementId]; - // Passing extra info such as creative id supported in 6.15.0+ - NSString *creativeIdentifier = self.creativeIdentifiers[placementID]; + NSString *creativeIdentifier = rewarded.creativeId; if ( ALSdk.versionCode >= 6150000 && [creativeIdentifier al_isValidString] ) { - [self performSelector: @selector(didDisplayAdForPlacementIdentifier:withExtraInfo:) - withObject: placementID - withObject: @{@"creative_id" : creativeIdentifier}]; - [self.creativeIdentifiers removeObjectForKey: placementID]; + [self.delegate didDisplayRewardedAdWithExtraInfo: @{@"creative_id" : creativeIdentifier}]; } else { - [self didDisplayAdForPlacementIdentifier: placementID]; + [self.delegate didDisplayRewardedAd]; } - - [self didStartRewardedVideoForPlacementIdentifier: placementID]; } -- (void)vungleTrackClickForPlacementID:(NSString *)placementID +- (void)rewardedAdDidFailToPresent:(VungleRewarded *)rewarded withError:(NSError *)error { - [self log: @"Ad clicked"]; - [self didClickAdForPlacementIdentifier: placementID]; + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"Rewarded ad (%@) failed to show with error: %@", rewarded.placementId, adapterError]; + [self.delegate didFailToDisplayRewardedAdWithError: adapterError]; } -- (void)vungleRewardUserForPlacementID:(NSString *)placementID +- (void)rewardedAdDidClick:(VungleRewarded *)rewarded { - [self log: @"Rewarded ad user did earn reward"]; - self.grantedReward = YES; + [self.parentAdapter log: @"Rewarded ad clicked: %@", rewarded.placementId]; + [self.delegate didClickRewardedAd]; } -- (void)vungleWillCloseAdForPlacementID:(NSString *)placementID +- (void)rewardedAdWillLeaveApplication:(VungleRewarded *)rewarded { - [self log: @"Ad will close"]; - - [self didCompleteRewardedVideoForPlacementIdentifier: placementID]; - - if ( self.grantedReward || [self shouldAlwaysRewardUserForPlacementIdentifier: placementID] ) - { - [self didRewardUserForPlacementIdentifier: placementID withReward: [self rewardForPlacementIdentifier: placementID]]; - self.grantedReward = NO; - } + [self.parentAdapter log: @"Rewarded ad will leave application: %@", rewarded.placementId]; } -- (void)vungleDidCloseAdForPlacementID:(NSString *)placementID +- (void)rewardedAdDidRewardUser:(VungleRewarded *)rewarded { - [self log: @"Ad did close"]; - [self didHideAdForPlacementIdentifier: placementID]; + [self.parentAdapter log: @"User earned reward: %@", rewarded.placementId]; + self.grantedReward = YES; } -- (void)vungleSDKDidInitialize +- (void)rewardedAdWillClose:(VungleRewarded *)rewarded { - [self log: @"Vungle SDK initialized"]; + [self.parentAdapter log: @"Rewarded ad will close: %@", rewarded.placementId]; +} + +- (void)rewardedAdDidClose:(VungleRewarded *)rewarded +{ + [self.delegate didCompleteRewardedAdVideo]; - if ( self.completionBlock ) + if ( [self hasGrantedReward] || [self.parentAdapter shouldAlwaysRewardUser] ) { - ALVungleIntializationStatus = MAAdapterInitializationStatusInitializedSuccess; - - self.completionBlock(ALVungleIntializationStatus, nil); - self.completionBlock = nil; + MAReward *reward = [self.parentAdapter reward]; + [self.parentAdapter log: @"Rewarded user with reward: %@", reward]; + [self.delegate didRewardUserWithReward: reward]; } - if ( self.oldCompletionHandler ) + [self.parentAdapter log: @"Rewarded ad hidden: %@", rewarded.placementId]; + [self.delegate didHideRewardedAd]; +} + +@end + +@implementation ALVungleMediationAdapterAdViewDelegate + +- (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter + format:(MAAdFormat *)adFormat + parameters:(id)parameters + andNotify:(id)delegate +{ + self = [super init]; + if ( self ) { - self.oldCompletionHandler(); - self.oldCompletionHandler = nil; + self.parentAdapter = parentAdapter; + self.adFormat = adFormat; + self.parameters = parameters; + self.delegate = delegate; } + return self; } -- (void)vungleSDKFailedToInitializeWithError:(NSError *)error +- (void)bannerAdDidLoad:(VungleBanner *)banner { - [self log: @"Vungle SDK failed to initialize with error: %@", error]; + [self.parentAdapter log: @"AdView loaded: %@", banner.placementId]; + [self.delegate didLoadAdForAdView: self.parentAdapter.adViewContainer]; - if ( self.completionBlock ) + if ( [banner canPlayAd] ) { - ALVungleIntializationStatus = MAAdapterInitializationStatusInitializedFailure; - NSString *errorString = [NSString stringWithFormat: @"%ld:%@", (long) error.code, error.localizedDescription]; - - self.completionBlock(ALVungleIntializationStatus, errorString); - self.completionBlock = nil; + [banner presentOn: self.parentAdapter.adViewContainer]; } - - if ( self.oldCompletionHandler ) + else { - self.oldCompletionHandler(); - self.oldCompletionHandler = nil; + [self.parentAdapter log: @"Failed to load ad view ad: ad not ready"]; + [self.delegate didFailToLoadAdViewAdWithError: MAAdapterError.adNotReady]; } } -#pragma mark - VungleSDKHBDelegate - -// This method is called when Vungle's SDK initializes to cache ads; it's also used as the load callback when [loadPlacementWithID:] is called -- (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable - placementID:(nullable NSString *)placementID - adMarkup:(nullable NSString *)adMarkup - error:(nullable NSError *)error +- (void)bannerAdDidFailToLoad:(VungleBanner *)banner withError:(NSError *)error { - [self vungleAdPlayabilityUpdate: isAdPlayable - placementID: placementID - error: error]; + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"AdView failed to load with error: %@", adapterError]; + [self.delegate didFailToLoadAdViewAdWithError: adapterError]; } -- (void)vungleWillShowAdForPlacementID:(NSString *)placementID adMarkup:(nullable NSString *)adMarkup +- (void)bannerAdWillPresent:(VungleBanner *)banner { - [self vungleWillShowAdForPlacementID: placementID]; + [self.parentAdapter log: @"AdView ad will present %@", banner.placementId]; } -- (void)vungleDidShowAdForPlacementID:(NSString *)placementID adMarkup:(nullable NSString *)adMarkup +- (void)bannerAdDidPresent:(VungleBanner *)banner { - // Old CIMP location. Caused discrepancies with Vungle. - [self vungleDidShowAdForPlacementID: placementID]; + [self.parentAdapter log: @"AdView ad shown %@", banner.placementId]; } -- (void)vungleAdViewedForPlacementID:(NSString *)placementID adMarkup:(NSString *)adMarkup +- (void)bannerAdDidTrackImpression:(VungleBanner *)banner { - [self vungleAdViewedForPlacement: placementID]; + [self.parentAdapter log: @"AdView ad impression tracked %@", banner.placementId]; + + NSString *creativeIdentifier = banner.creativeId; + if ( ALSdk.versionCode >= 6150000 && [creativeIdentifier al_isValidString] ) + { + [self.delegate didDisplayAdViewAdWithExtraInfo: @{@"creative_id" : creativeIdentifier}]; + } + else + { + [self.delegate didDisplayAdViewAd]; + } } -- (void)vungleTrackClickForPlacementID:(NSString *)placementID adMarkup:(nullable NSString *)adMarkup +- (void)bannerAdDidClick:(VungleBanner *)banner { - [self vungleTrackClickForPlacementID: placementID]; + [self.parentAdapter log: @"AdView ad clicked %@", banner.placementId]; + [self.delegate didClickAdViewAd]; } -- (void)vungleRewardUserForPlacementID:(NSString *)placementID adMarkup:(nullable NSString *)adMarkup +- (void)bannerAdWillLeaveApplication:(VungleBanner *)banner { - [self vungleRewardUserForPlacementID: placementID]; + [self.parentAdapter log: @"AdView ad will leave application %@", banner.placementId]; } -- (void)vungleWillCloseAdForPlacementID:(NSString *)placementID adMarkup:(nullable NSString *)adMarkup +- (void)bannerAdDidFailToPresent:(VungleBanner *)banner withError:(NSError *)error { - [self vungleWillCloseAdForPlacementID: placementID]; + MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; + [self.parentAdapter log: @"AdView ad failed to present with error: %@", adapterError]; + [self.delegate didFailToDisplayAdViewAdWithError: adapterError]; } -- (void)vungleDidCloseAdForPlacementID:(NSString *)placementID adMarkup:(nullable NSString *)adMarkup +- (void)bannerAdWillClose:(VungleBanner *)banner { - [self vungleDidCloseAdForPlacementID: placementID]; + [self.parentAdapter log: @"AdView ad will close %@", banner.placementId]; } -#pragma mark - VungleSDKCreativeTracking - -- (void)vungleCreative:(nullable NSString *)creativeID readyForPlacement:(nullable NSString *)placementID +- (void)bannerAdDidClose:(VungleBanner *)banner { - [self log: @"Vungle creative with creativeID: %@ ready for placement: %@", creativeID, placementID]; - if ( [creativeID al_isValidString] && [placementID al_isValidString] ) - { - self.creativeIdentifiers[placementID] = creativeID; - } + [self.parentAdapter log: @"AdView ad hidden %@", banner.placementId]; + [self.delegate didHideAdViewAd]; } @end @@ -1141,7 +979,7 @@ - (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter return self; } -- (void)nativeAdDidLoad:(VungleNativeAd *)nativeAd +- (void)nativeAdDidLoad:(VungleNative *)nativeAd { if ( !nativeAd || self.parentAdapter.nativeAd != nativeAd ) { @@ -1162,7 +1000,7 @@ - (void)nativeAdDidLoad:(VungleNativeAd *)nativeAd [self.parentAdapter log: @"Native %@ ad loaded: %@", self.adFormat, self.placementIdentifier]; dispatchOnMainQueue(^{ - VungleMediaView *mediaView = [[VungleMediaView alloc] init]; + MediaView *mediaView = [[MediaView alloc] init]; MAVungleNativeAd *maxVungleNativeAd = [[MAVungleNativeAd alloc] initWithParentAdapter: self.parentAdapter adFormat: self.adFormat builderBlock:^(MANativeAdBuilder *builder) { builder.title = nativeAd.title; @@ -1216,20 +1054,29 @@ - (void)nativeAdDidLoad:(VungleNativeAd *)nativeAd }); } -- (void)nativeAd:(VungleNativeAd *)nativeAd didFailWithError:(NSError *)error +- (void)nativeAd:(VungleNative *)nativeAd didFailWithError:(NSError *)error { MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; [self.parentAdapter log: @"Native %@ ad failed to load with error: %@", self.adFormat, adapterError]; [self.delegate didFailToLoadAdViewAdWithError: adapterError]; } -- (void)nativeAdDidTrackImpression:(VungleNativeAd *)nativeAd +- (void)nativeAdDidTrackImpression:(VungleNative *)nativeAd { [self.parentAdapter log: @"Native %@ ad shown: %@", self.adFormat, self.placementIdentifier]; - [self.delegate didDisplayAdViewAd]; + + NSString *creativeIdentifier = nativeAd.creativeId; + if ( ALSdk.versionCode >= 6150000 && [creativeIdentifier al_isValidString] ) + { + [self.delegate didDisplayAdViewAdWithExtraInfo: @{@"creative_id" : creativeIdentifier}]; + } + else + { + [self.delegate didDisplayAdViewAd]; + } } -- (void)nativeAdDidClick:(VungleNativeAd *)nativeAd +- (void)nativeAdDidClick:(VungleNative *)nativeAd { [self.parentAdapter log: @"Native %@ ad clicked: %@", self.adFormat, self.placementIdentifier]; [self.delegate didClickAdViewAd]; @@ -1254,7 +1101,7 @@ - (instancetype)initWithParentAdapter:(ALVungleMediationAdapter *)parentAdapter return self; } -- (void)nativeAdDidLoad:(VungleNativeAd *)nativeAd +- (void)nativeAdDidLoad:(VungleNative *)nativeAd { if ( !nativeAd || self.parentAdapter.nativeAd != nativeAd ) { @@ -1277,7 +1124,7 @@ - (void)nativeAdDidLoad:(VungleNativeAd *)nativeAd [self.parentAdapter log: @"Native ad loaded: %@", self.placementIdentifier]; dispatchOnMainQueue(^{ - VungleMediaView *mediaView = [[VungleMediaView alloc] init]; + MediaView *mediaView = [[MediaView alloc] init]; MANativeAd *maxNativeAd = [[MAVungleNativeAd alloc] initWithParentAdapter: self.parentAdapter adFormat: MAAdFormat.native builderBlock:^(MANativeAdBuilder *builder) { builder.title = nativeAd.title; @@ -1300,20 +1147,28 @@ - (void)nativeAdDidLoad:(VungleNativeAd *)nativeAd }); } -- (void)nativeAd:(VungleNativeAd *)nativeAd didFailWithError:(NSError *)error +- (void)nativeAd:(VungleNative *)nativeAd didFailWithError:(NSError *)error { MAAdapterError *adapterError = [ALVungleMediationAdapter toMaxError: error]; [self.parentAdapter log: @"Native ad failed to load with error: %@", adapterError]; [self.delegate didFailToLoadNativeAdWithError: adapterError]; } -- (void)nativeAdDidTrackImpression:(VungleNativeAd *)nativeAd +- (void)nativeAdDidTrackImpression:(VungleNative *)nativeAd { [self.parentAdapter log: @"Native ad shown: %@", self.placementIdentifier]; - [self.delegate didDisplayNativeAdWithExtraInfo: nil]; + NSString *creativeIdentifier = nativeAd.creativeId; + if ( ALSdk.versionCode >= 6150000 && [creativeIdentifier al_isValidString] ) + { + [self.delegate didDisplayNativeAdWithExtraInfo: @{@"creative_id" : creativeIdentifier}]; + } + else + { + [self.delegate didDisplayNativeAdWithExtraInfo: nil]; + } } -- (void)nativeAdDidClick:(VungleNativeAd *)nativeAd +- (void)nativeAdDidClick:(VungleNative *)nativeAd { [self.parentAdapter log: @"Native ad clicked: %@", self.placementIdentifier]; [self.delegate didClickNativeAd]; @@ -1340,7 +1195,7 @@ - (void)prepareViewForInteraction:(MANativeAdView *)maxNativeAdView - (BOOL)prepareForInteractionClickableViews:(NSArray *)clickableViews withContainer:(UIView *)container { - VungleNativeAd *nativeAd = self.parentAdapter.nativeAd; + VungleNative *nativeAd = self.parentAdapter.nativeAd; if ( !nativeAd ) { [self.parentAdapter e: @"Failed to register native ad views: native ad is nil."]; @@ -1359,11 +1214,11 @@ - (BOOL)prepareForInteractionClickableViews:(NSArray *)clickableViews [self.parentAdapter d: @"Preparing views for interaction: %@ with container: %@", clickableViews, container]; - [nativeAd registerViewForInteraction: container - mediaView: (VungleMediaView *) self.mediaView - iconImageView: iconImageView - viewController: [ALUtils topViewControllerFromKeyWindow] - clickableViews: clickableViews]; + [nativeAd registerViewForInteractionWithView: container + mediaView: (MediaView *) self.mediaView + iconImageView: iconImageView + viewController: [ALUtils topViewControllerFromKeyWindow] + clickableViews: clickableViews]; return YES; }