diff --git a/VerizonAds/AppLovinMediationVerizonAdsAdapter.podspec b/VerizonAds/AppLovinMediationVerizonAdsAdapter.podspec index 31b6ab70d3..f56ff6b64a 100644 --- a/VerizonAds/AppLovinMediationVerizonAdsAdapter.podspec +++ b/VerizonAds/AppLovinMediationVerizonAdsAdapter.podspec @@ -5,8 +5,8 @@ s.authors = 'AppLovin Corporation' => 'devsupport@applovin.com' } s.name = 'AppLovinMediationVerizonAdsAdapter' -s.version = '1.14.2.10' -s.platform = :ios, '9.0' +s.version = '2.0.0.0' +s.platform = :ios, '11.0' s.summary = 'Verizon Ads adapter used for mediation with the AppLovin MAX SDK' s.homepage = "https://github.com/CocoaPods/Specs/search?o=desc&q=#{s.name}&s=indexed" s.license = @@ -29,14 +29,16 @@ s.source = s.vendored_frameworks = "#{s.name}-#{s.version}/#{s.name}.xcframework" -s.dependency 'Verizon-Ads-StandardEdition', '= 1.14.2' +s.dependency 'Yahoo-Mobile-SDK', '= 1.0.0' s.dependency 'AppLovinSDK' +s.swift_version = '5.0' + 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' + 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } s.description = <<-DESC diff --git a/VerizonAds/CHANGELOG.md b/VerizonAds/CHANGELOG.md index d9fc2616d7..7e49c7076c 100644 --- a/VerizonAds/CHANGELOG.md +++ b/VerizonAds/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.0.0.0 +* Certified with Yahoo Mobile SDK 1.0.0. +* Remove arm64 simulator slice which the Yahoo-Ads SDK does not support. + ## 1.14.2.10 * Add support for providing native media content aspect ratio in `MANativeAdView`. * Distribute adapter as an XCFramework. diff --git a/VerizonAds/VerizonAdsAdapter.xcodeproj/project.pbxproj b/VerizonAds/VerizonAdsAdapter.xcodeproj/project.pbxproj index 6dda2499da..e070e329d5 100644 --- a/VerizonAds/VerizonAdsAdapter.xcodeproj/project.pbxproj +++ b/VerizonAds/VerizonAdsAdapter.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1D5748D821C79E13004C8981 /* ALVerizonAdsMediationAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A561CD5219BB58300E3749A /* ALVerizonAdsMediationAdapter.m */; }; + 2DAF6C9F6890C02BEF425EE0 /* Pods_VerizonAdsAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F52A0728C94E486B748F864 /* Pods_VerizonAdsAdapter.framework */; }; 6A561CEA219BB5D400E3749A /* AppLovinSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D31B64D219BA4E600875D92 /* AppLovinSDK.framework */; }; /* End PBXBuildFile section */ @@ -45,6 +46,9 @@ 6A561CEF219BB5D400E3749A /* libVerizonAdsAdapter.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libVerizonAdsAdapter.a; sourceTree = BUILT_PRODUCTS_DIR; }; 6A5A632E21C0872C00B755D7 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = SOURCE_ROOT; }; 6A5A632F21C0872D00B755D7 /* AppLovinMediationVerizonAdsAdapter.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = AppLovinMediationVerizonAdsAdapter.podspec; sourceTree = SOURCE_ROOT; }; + 857940D3352DC05E44E4CB88 /* Pods-VerizonAdsAdapter.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VerizonAdsAdapter.debug.xcconfig"; path = "Target Support Files/Pods-VerizonAdsAdapter/Pods-VerizonAdsAdapter.debug.xcconfig"; sourceTree = ""; }; + 9F52A0728C94E486B748F864 /* Pods_VerizonAdsAdapter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_VerizonAdsAdapter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + AB728BEF776C7734E33A1B74 /* Pods-VerizonAdsAdapter.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VerizonAdsAdapter.release.xcconfig"; path = "Target Support Files/Pods-VerizonAdsAdapter/Pods-VerizonAdsAdapter.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -53,6 +57,7 @@ buildActionMask = 2147483647; files = ( 6A561CEA219BB5D400E3749A /* AppLovinSDK.framework in Frameworks */, + 2DAF6C9F6890C02BEF425EE0 /* Pods_VerizonAdsAdapter.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -77,6 +82,7 @@ 1D9AE8EA21423C7E00080475 /* SystemConfiguration.framework */, 1D9AE8E821423C7E00080475 /* UIKit.framework */, 1D9AE8E721423C7E00080475 /* WebKit.framework */, + 9F52A0728C94E486B748F864 /* Pods_VerizonAdsAdapter.framework */, ); name = Frameworks; sourceTree = ""; @@ -88,6 +94,7 @@ 6A12947F21C086760052F283 /* Supporting Files */, 1D97FB861FBCF38B00D6C309 /* Products */, 1D2303A61FBCF4C7001939D7 /* Frameworks */, + FEC1D2F3D573711B4AFC822D /* Pods */, ); sourceTree = ""; }; @@ -117,6 +124,16 @@ path = VerizonAdsAdapter; sourceTree = ""; }; + FEC1D2F3D573711B4AFC822D /* Pods */ = { + isa = PBXGroup; + children = ( + 857940D3352DC05E44E4CB88 /* Pods-VerizonAdsAdapter.debug.xcconfig */, + AB728BEF776C7734E33A1B74 /* Pods-VerizonAdsAdapter.release.xcconfig */, + ); + name = Pods; + path = "../../iOS-Workspace/Pods"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -124,6 +141,7 @@ isa = PBXNativeTarget; buildConfigurationList = 6A561CEC219BB5D400E3749A /* Build configuration list for PBXNativeTarget "VerizonAdsAdapter" */; buildPhases = ( + 167B969CD977BF1FB79575C7 /* [CP] Check Pods Manifest.lock */, 6A561CE7219BB5D400E3749A /* Sources */, 6A561CE9219BB5D400E3749A /* Frameworks */, 6A561CEB219BB5D400E3749A /* Copy Files */, @@ -169,6 +187,31 @@ }; /* End PBXProject section */ +/* Begin PBXShellScriptBuildPhase section */ + 167B969CD977BF1FB79575C7 /* [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-VerizonAdsAdapter-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 */ 6A561CE7219BB5D400E3749A /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -300,17 +343,18 @@ }; 6A561CED219BB5D400E3749A /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 857940D3352DC05E44E4CB88 /* Pods-VerizonAdsAdapter.debug.xcconfig */; buildSettings = { BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CODE_SIGN_STYLE = Manual; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = X8JXXK4FF5; - EXCLUDED_ARCHS = i386; - FRAMEWORK_SEARCH_PATHS = "../../iOS-Workspace/Pods/**"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + EXCLUDED_ARCHS = "i386 $(inherited)"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LIBRARY_SEARCH_PATHS = "$(inherited)"; ONLY_ACTIVE_ARCH = YES; - OTHER_CFLAGS = "-fembed-bitcode-marker"; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -321,17 +365,18 @@ }; 6A561CEE219BB5D400E3749A /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = AB728BEF776C7734E33A1B74 /* Pods-VerizonAdsAdapter.release.xcconfig */; buildSettings = { BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CODE_SIGN_STYLE = Manual; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = X8JXXK4FF5; - EXCLUDED_ARCHS = i386; - FRAMEWORK_SEARCH_PATHS = "../../iOS-Workspace/Pods/**"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + EXCLUDED_ARCHS = "i386 $(inherited)"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LIBRARY_SEARCH_PATHS = "$(inherited)"; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = "$(inherited)"; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.h b/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.h index 70fdef5d14..90f39a5e27 100644 --- a/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.h +++ b/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.h @@ -8,6 +8,6 @@ #import -@interface ALVerizonAdsMediationAdapter : ALMediationAdapter +@interface ALVerizonAdsMediationAdapter : ALMediationAdapter @end diff --git a/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.m b/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.m index 282349487b..ceb4630d1b 100644 --- a/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.m +++ b/VerizonAds/VerizonAdsAdapter/ALVerizonAdsMediationAdapter.m @@ -7,21 +7,15 @@ // #import "ALVerizonAdsMediationAdapter.h" -#import -#import -#import -#import -#import -#import -#import -#import +#import -#define ADAPTER_VERSION @"1.14.2.10" +// Major version number is '2' since certifying against the rebranded Yahoo SDK +#define ADAPTER_VERSION @"2.0.0.0" /** * Dedicated delegate object for Verizon Ads interstitial ads. */ -@interface ALVerizonAdsMediationAdapterInterstitialDelegate : NSObject +@interface ALVerizonAdsMediationAdapterInterstitialDelegate : NSObject @property (nonatomic, weak) ALVerizonAdsMediationAdapter *parentAdapter; @property (nonatomic, strong) id delegate; - (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdapter andNotify:(id)delegate; @@ -31,7 +25,7 @@ - (instancetype)init NS_UNAVAILABLE; /** * Dedicated delegate object for Verizon Ads rewarded ads. */ -@interface ALVerizonAdsMediationAdapterRewardedDelegate : NSObject +@interface ALVerizonAdsMediationAdapterRewardedDelegate : NSObject @property (nonatomic, weak) ALVerizonAdsMediationAdapter *parentAdapter; @property (nonatomic, strong) id delegate; @property (nonatomic, assign, getter=hasGrantedReward) BOOL grantedReward; @@ -42,7 +36,7 @@ - (instancetype)init NS_UNAVAILABLE; /** * Dedicated delegate object for Verizon Ads AdView ads. */ -@interface ALVerizonAdsMediationAdapterInlineAdViewDelegate : NSObject +@interface ALVerizonAdsMediationAdapterInlineAdViewDelegate : NSObject @property (nonatomic, weak) ALVerizonAdsMediationAdapter *parentAdapter; @property (nonatomic, strong) id delegate; - (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdapter andNotify:(id)delegate; @@ -52,7 +46,7 @@ - (instancetype)init NS_UNAVAILABLE; /** * Dedicated delegate object for Verizon Ads native ads. */ -@interface ALVerizonAdsMediationAdapterNativeAdDelegate : NSObject +@interface ALVerizonAdsMediationAdapterNativeAdDelegate : NSObject @property (nonatomic, weak) ALVerizonAdsMediationAdapter *parentAdapter; @property (nonatomic, strong) NSDictionary *serverParameters; @property (nonatomic, strong) id delegate; @@ -63,78 +57,66 @@ - (instancetype)init NS_UNAVAILABLE; @end @interface MAVerizonNativeAd : MANativeAd -@property (nonatomic, weak) ALVerizonAdsMediationAdapter *parentAdapter; -@property (nonatomic, strong) id delegate; -- (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdapter - andNotify:(id)delegate - builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock; +@property (nonatomic, weak) ALVerizonAdsMediationAdapter *parentAdapter; +- (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdapter builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock; - (instancetype)initWithFormat:(MAAdFormat *)format builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock NS_UNAVAILABLE; @end @interface ALVerizonAdsMediationAdapter() // Interstitial -@property (nonatomic, strong) VASInterstitialAd *interstitialAd; +@property (nonatomic, strong) YASInterstitialAd *interstitialAd; @property (nonatomic, strong) ALVerizonAdsMediationAdapterInterstitialDelegate *interstitialDelegate; // Rewarded -@property (nonatomic, strong) VASInterstitialAd *rewardedAd; +@property (nonatomic, strong) YASInterstitialAd *rewardedAd; @property (nonatomic, strong) ALVerizonAdsMediationAdapterRewardedDelegate *rewardedDelegate; // AdView -@property (nonatomic, strong) VASInlineAdView *inlineAdView; +@property (nonatomic, strong) YASInlineAdView *inlineAdView; @property (nonatomic, strong) ALVerizonAdsMediationAdapterInlineAdViewDelegate *inlineAdViewDelegate; // Native -@property (nonatomic, strong) VASNativeAd *nativeAd; +@property (nonatomic, strong) YASNativeAd *nativeAd; @property (nonatomic, strong) ALVerizonAdsMediationAdapterNativeAdDelegate *nativeAdDelegate; @property (nonatomic, weak) MANativeAdView *nativeAdView; -@property (nonatomic, strong) UITapGestureRecognizer *titleGestureRecognizer; -@property (nonatomic, strong) UITapGestureRecognizer *advertiserGestureRecognizer; -@property (nonatomic, strong) UITapGestureRecognizer *bodyGestureRecognizer; -@property (nonatomic, strong) UITapGestureRecognizer *iconGestureRecognizer; -@property (nonatomic, strong) UITapGestureRecognizer *ctaGestureRecognizer; @end @implementation ALVerizonAdsMediationAdapter -static NSTimeInterval const kDefaultImageTaskTimeoutSeconds = 10.0; + +static NSArray *kNativeAdAdTypes; // Event IDs static NSString *const kMAVideoCompleteEventId = @"onVideoComplete"; static NSString *const kMAAdImpressionEventId = @"adImpression"; -#pragma mark - MAAdapter Methods - -- (void)initializeWithParameters:(id)parameters withCompletionHandler:(void (^)(void))completionHandler ++ (void)initialize { - if ( ![[VASAds sharedInstance] isInitialized] ) - { - NSString *siteID = [parameters.serverParameters al_stringForKey: @"site_id"]; - [self log: @"Initializing Verizon Ads SDK with site id: %@...", siteID]; - - [VASAds initializeWithSiteId: siteID]; - - // ...GDPR settings, which is part of verizon Ads SDK data, should be established after initialization and prior to making any ad requests... (https://sdk.verizonmedia.com/gdpr-coppa.html) - [self updateVerizonAdsSDKDataWithAdapterParameters: parameters]; - } + [super initialize]; - completionHandler(); + kNativeAdAdTypes = @[@"simpleImage", @"simpleVideo"]; } -- (void)initializeWithParameters:(id)parameters completionHandler:(void (^)(MAAdapterInitializationStatus, NSString * _Nullable))completionHandler +#pragma mark - MAAdapter Methods + +- (void)initializeWithParameters:(id)parameters completionHandler:(void (^)(MAAdapterInitializationStatus, NSString *_Nullable))completionHandler { MAAdapterInitializationStatus status; - if ( ![[VASAds sharedInstance] isInitialized] ) + + if ( ![[YASAds sharedInstance] isInitialized] ) { - [self log: @"Initializing Verizon Ads SDK..."]; + [self log: @"Initializing SDK..."]; + + YASLogLevel logLevel = [parameters isTesting] ? YASLogLevelVerbose : YASLogLevelError; + [YASAds setLogLevel: logLevel]; NSString *siteID = [parameters.serverParameters al_stringForKey: @"site_id"]; - BOOL initialized = [VASAds initializeWithSiteId: siteID]; + BOOL initialized = [YASAds initializeWithSiteId: siteID]; status = initialized ? MAAdapterInitializationStatusInitializedSuccess : MAAdapterInitializationStatusInitializedFailure; // ...GDPR settings, which is part of verizon Ads SDK data, should be established after initialization and prior to making any ad requests... (https://sdk.verizonmedia.com/gdpr-coppa.html) - [self updateVerizonAdsSDKDataWithAdapterParameters: parameters]; + [self updatePrivacyStatesForParameters: parameters]; } else { @@ -146,8 +128,7 @@ - (void)initializeWithParameters:(id)paramete - (NSString *)SDKVersion { - // NOTE: Verizon Ads SDK returns an empty string if attempting to retrieve if not initialized. - return [[VASAds sharedInstance].configuration stringForDomain: @"com.verizon.ads" key: @"editionVersion" withDefault: @""]; + return [YASAds sdkInfo].editionId; } - (NSString *)adapterVersion @@ -157,10 +138,6 @@ - (NSString *)adapterVersion - (void)destroy { - [self.inlineAdView destroy]; - self.inlineAdView = nil; - self.inlineAdViewDelegate = nil; - [self.interstitialAd destroy]; self.interstitialAd = nil; self.interstitialDelegate = nil; @@ -169,42 +146,53 @@ - (void)destroy self.rewardedAd = nil; self.rewardedDelegate = nil; + [self.inlineAdView destroy]; + self.inlineAdView = nil; + self.inlineAdViewDelegate = nil; + [self.nativeAd destroy]; self.nativeAd = nil; self.nativeAdDelegate = nil; - // Cleanup gesture recognizers set in [prepareViewForInteraction:] - [self.nativeAdView.titleLabel removeGestureRecognizer: self.titleGestureRecognizer]; - [self.nativeAdView.advertiserLabel removeGestureRecognizer: self.advertiserGestureRecognizer]; - [self.nativeAdView.bodyLabel removeGestureRecognizer: self.bodyGestureRecognizer]; - [self.nativeAdView.iconImageView removeGestureRecognizer: self.iconGestureRecognizer]; - [self.nativeAdView.callToActionButton removeGestureRecognizer: self.ctaGestureRecognizer]; - self.nativeAdView = nil; - self.titleGestureRecognizer = nil; - self.advertiserGestureRecognizer = nil; - self.bodyGestureRecognizer = nil; - self.iconGestureRecognizer = nil; - self.ctaGestureRecognizer = nil; +} + +#pragma mark - MASignalProvider + +- (void)collectSignalWithParameters:(id)parameters andNotify:(id)delegate +{ + [self log: @"Collecting signal..."]; + + NSString *token = [[YASAds sharedInstance] biddingTokenTrimmedToSize: 4000]; + if ( !token ) + { + NSString *errorMessage = @"Yahoo SDK not initialized; failed to return a bid."; + [delegate didFailToCollectSignalWithErrorMessage: errorMessage]; + + return; + } + + [delegate didCollectSignal: token]; } #pragma mark - MAInterstitialAdapter Methods - (void)loadInterstitialAdForParameters:(id)parameters andNotify:(id)delegate { - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading interstitial ad for placement: '%@'...", placementIdentifier]; + NSString *placementId = parameters.thirdPartyAdPlacementIdentifier; + NSString *bidResponse = parameters.bidResponse; + [self log: @"Loading %@ interstitial ad for placement: %@...", ([bidResponse al_isValidString] ? @"bidding" : @""), placementId]; - self.interstitialDelegate = [[ALVerizonAdsMediationAdapterInterstitialDelegate alloc] initWithParentAdapter: self andNotify: delegate]; - VASInterstitialAdFactory *interstitialFactory = [[VASInterstitialAdFactory alloc] initWithPlacementId: placementIdentifier - vasAds: [VASAds sharedInstance] - delegate: self.interstitialDelegate]; - interstitialFactory.requestMetadata = [self createRequestMetadataForForServerParameters: parameters.serverParameters andBidResponse: parameters.bidResponse]; + [self updatePrivacyStatesForParameters: parameters]; - [self updateVerizonAdsSDKDataWithAdapterParameters: parameters]; + self.interstitialDelegate = [[ALVerizonAdsMediationAdapterInterstitialDelegate alloc] initWithParentAdapter: self andNotify: delegate]; + self.interstitialAd = [[YASInterstitialAd alloc] initWithPlacementId: placementId]; + self.interstitialAd.delegate = self.interstitialDelegate; - [self log: @"Loading %@ interstitial ad...", [parameters.bidResponse al_isValidString] ? @"Bidding" : @"mediated"]; - [interstitialFactory load: self.interstitialDelegate]; + YASRequestMetadata *requestMetadata = [self createRequestMetadataForBidResponse: bidResponse]; + YASInterstitialPlacementConfig *placementConfig = [[YASInterstitialPlacementConfig alloc] initWithPlacementId: placementId + requestMetadata: requestMetadata]; + [self.interstitialAd loadWithPlacementConfig: placementConfig]; } - (void)showInterstitialAdForParameters:(id)parameters andNotify:(id)delegate @@ -229,6 +217,7 @@ - (void)showInterstitialAdForParameters:(id)paramet presentingViewController = [ALUtils topViewControllerFromKeyWindow]; } + [self.interstitialAd setImmersiveEnabled: YES]; [self.interstitialAd showFromViewController: presentingViewController]; } @@ -236,19 +225,20 @@ - (void)showInterstitialAdForParameters:(id)paramet - (void)loadRewardedAdForParameters:(id)parameters andNotify:(id)delegate { - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading rewarded ad for placement: '%@'...", placementIdentifier]; + NSString *placementId = parameters.thirdPartyAdPlacementIdentifier; + NSString *bidResponse = parameters.bidResponse; + [self log: @"Loading %@ interstitial ad for placement: %@...", ([bidResponse al_isValidString] ? @"bidding" : @""), placementId]; - self.rewardedDelegate = [[ALVerizonAdsMediationAdapterRewardedDelegate alloc] initWithParentAdapter: self andNotify: delegate]; - VASInterstitialAdFactory *rewardedFactory = [[VASInterstitialAdFactory alloc] initWithPlacementId: placementIdentifier - vasAds: [VASAds sharedInstance] - delegate: self.rewardedDelegate]; - rewardedFactory.requestMetadata = [self createRequestMetadataForForServerParameters: parameters.serverParameters andBidResponse: parameters.bidResponse]; + [self updatePrivacyStatesForParameters: parameters]; - [self updateVerizonAdsSDKDataWithAdapterParameters: parameters]; + self.rewardedDelegate = [[ALVerizonAdsMediationAdapterRewardedDelegate alloc] initWithParentAdapter: self andNotify: delegate]; + self.rewardedAd = [[YASInterstitialAd alloc] initWithPlacementId: placementId]; + self.rewardedAd.delegate = self.rewardedDelegate; - [self log: @"Loading %@ rewarded ad...", [parameters.bidResponse al_isValidString] ? @"Bidding" : @"mediated"]; - [rewardedFactory load: self.interstitialDelegate]; + YASRequestMetadata *requestMetadata = [self createRequestMetadataForBidResponse: bidResponse]; + YASInterstitialPlacementConfig *placementConfig = [[YASInterstitialPlacementConfig alloc] initWithPlacementId: placementId + requestMetadata: requestMetadata]; + [self.rewardedAd loadWithPlacementConfig: placementConfig]; } - (void)showRewardedAdForParameters:(id)parameters andNotify:(id)delegate @@ -275,6 +265,7 @@ - (void)showRewardedAdForParameters:(id)parameters presentingViewController = [ALUtils topViewControllerFromKeyWindow]; } + [self.rewardedAd setImmersiveEnabled: YES]; [self.rewardedAd showFromViewController: presentingViewController]; } @@ -283,20 +274,21 @@ - (void)showRewardedAdForParameters:(id)parameters - (void)loadAdViewAdForParameters:(id)parameters adFormat:(MAAdFormat *)adFormat andNotify:(id)delegate { NSString *bidResponse = parameters.bidResponse; - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading %@%@ for placement: %@...", ( [bidResponse al_isValidString] ? @"bidding " : @""), adFormat.label, placementIdentifier]; + NSString *placementId = parameters.thirdPartyAdPlacementIdentifier; + [self log: @"Loading %@%@ for placement: %@...", ([bidResponse al_isValidString] ? @"bidding " : @""), adFormat.label, placementId]; - VASInlineAdSize *adSize = [self adSizeFromAdFormat: adFormat]; - self.inlineAdViewDelegate = [[ALVerizonAdsMediationAdapterInlineAdViewDelegate alloc] initWithParentAdapter: self andNotify: delegate]; - VASInlineAdFactory *inlineAdFactory = [[VASInlineAdFactory alloc] initWithPlacementId: placementIdentifier - adSizes: @[adSize] - vasAds: [VASAds sharedInstance] - delegate: self.inlineAdViewDelegate]; - inlineAdFactory.requestMetadata = [self createRequestMetadataForForServerParameters: parameters.serverParameters andBidResponse: bidResponse]; + [self updatePrivacyStatesForParameters: parameters]; - [self updateVerizonAdsSDKDataWithAdapterParameters: parameters]; + self.inlineAdViewDelegate = [[ALVerizonAdsMediationAdapterInlineAdViewDelegate alloc] initWithParentAdapter: self andNotify: delegate]; + self.inlineAdView = [[YASInlineAdView alloc] initWithPlacementId: placementId]; + self.inlineAdView.delegate = self.inlineAdViewDelegate; - [inlineAdFactory load: self.inlineAdViewDelegate]; + YASRequestMetadata *requestMetadata = [self createRequestMetadataForBidResponse: bidResponse]; + YASInlineAdSize *adSize = [self adSizeFromAdFormat: adFormat]; + YASInlinePlacementConfig *placementConfig = [[YASInlinePlacementConfig alloc] initWithPlacementId: placementId + requestMetadata: requestMetadata + adSizes: @[adSize]]; + [self.inlineAdView loadWithPlacementConfig: placementConfig]; } #pragma mark - MANativeAdAdapter Methods @@ -304,54 +296,33 @@ - (void)loadAdViewAdForParameters:(id)parameters ad - (void)loadNativeAdForParameters:(id)parameters andNotify:(id)delegate { NSString *bidResponse = parameters.bidResponse; - NSString *placementIdentifier = parameters.thirdPartyAdPlacementIdentifier; - [self log: @"Loading native %@for placement: %@...", ( [bidResponse al_isValidString] ? @"bidding " : @""), placementIdentifier]; + NSString *placementId = parameters.thirdPartyAdPlacementIdentifier; + [self log: @"Loading %@ native for placement: %@...", ([bidResponse al_isValidString] ? @"bidding " : @""), placementId]; self.nativeAdDelegate = [[ALVerizonAdsMediationAdapterNativeAdDelegate alloc] initWithParentAdapter: self serverParameters: parameters.serverParameters andNotify: delegate]; - VASNativeAdFactory *nativeAdFactory = [[VASNativeAdFactory alloc] initWithPlacementId: placementIdentifier - adTypes: @[@"simpleImage", @"simpleVideo"] - vasAds: [VASAds sharedInstance] - delegate: self.nativeAdDelegate]; - nativeAdFactory.requestMetadata = [self createRequestMetadataForForServerParameters: parameters.serverParameters andBidResponse: bidResponse]; - [self updateVerizonAdsSDKDataWithAdapterParameters: parameters]; + self.nativeAd = [[YASNativeAd alloc] initWithPlacementId: placementId]; + self.nativeAd.delegate = self.nativeAdDelegate; - [nativeAdFactory load: self.nativeAdDelegate]; -} - -#pragma mark - Signal Provider Protocol - -- (void)collectSignalWithParameters:(id)parameters andNotify:(id)delegate -{ - [self log: @"Collecting signal..."]; + [self updatePrivacyStatesForParameters: parameters]; - NSString *token = [[VASAds sharedInstance] biddingTokenTrimmedToSize: 4000]; - if ( !token ) - { - NSString *errorMessage = @"VerizonAds SDK not initialized; failed to return a bid."; - [delegate didFailToCollectSignalWithErrorMessage: errorMessage]; - - return; - } - - [delegate didCollectSignal: token]; + YASRequestMetadata *requestMetadata = [self createRequestMetadataForBidResponse: bidResponse]; + YASNativePlacementConfig *placementConfig = [[YASNativePlacementConfig alloc] initWithPlacementId: placementId + requestMetadata: requestMetadata + nativeAdTypes: kNativeAdAdTypes]; + [self.nativeAd loadWithPlacementConfig: placementConfig]; } #pragma mark - Shared Methods -- (void)updateVerizonAdsSDKDataWithAdapterParameters:(id)parameters +- (void)updatePrivacyStatesForParameters:(id)parameters { - VASLogLevel logLevel = [parameters isTesting] ? VASLogLevelVerbose : VASLogLevelError; - [VASAds setLogLevel: logLevel]; - - VASDataPrivacyBuilder *builder = [[VASDataPrivacyBuilder alloc] initWithDataPrivacy: VASAds.sharedInstance.dataPrivacy]; - NSNumber *isAgeRestrictedUser = [self privacySettingForSelector: @selector(isAgeRestrictedUser) fromParameters: parameters]; if ( isAgeRestrictedUser ) { - builder.coppa.applies = isAgeRestrictedUser.boolValue; + [[YASAds sharedInstance] applyCoppa]; } if ( ALSdk.versionCode >= 61100 ) @@ -359,15 +330,13 @@ - (void)updateVerizonAdsSDKDataWithAdapterParameters:(id)pa NSNumber *isDoNotSell = [self privacySettingForSelector: @selector(isDoNotSell) fromParameters: parameters]; if ( isDoNotSell ) { - builder.ccpa.privacy = isDoNotSell ? @"1YY-" : @"1YN-"; + [[YASAds sharedInstance] addConsent: [[YASCcpaConsent alloc] initWithConsentString: isDoNotSell ? @"1YY-" : @"1YN-"]]; } else { - builder.ccpa.privacy = @"1---"; + [[YASAds sharedInstance] addConsent: [[YASCcpaConsent alloc] initWithConsentString: @"1---"]]; } } - - [[VASAds sharedInstance] setDataPrivacy: [builder build]]; } - (nullable NSNumber *)privacySettingForSelector:(SEL)selector fromParameters:(id)parameters @@ -397,113 +366,52 @@ - (nullable NSNumber *)privacySettingForSelector:(SEL)selector fromParameters:(i } } -- (VASRequestMetadata *)createRequestMetadataForForServerParameters:(NSDictionary *)serverParameters andBidResponse:(NSString *)bidResponse +- (YASRequestMetadata *)createRequestMetadataForBidResponse:(NSString *)bidResponse { - VASRequestMetadataBuilder *builder = [[VASRequestMetadataBuilder alloc] init]; - - if ( [bidResponse al_isValidString] ) - { - NSMutableDictionary *placementData = [@{@"adContent" : bidResponse, - @"overrideWaterfallProvider" : @"waterfallprovider/sideloading"} mutableCopy]; - [builder setPlacementData: placementData]; - } - + YASRequestMetadataBuilder *builder = [[YASRequestMetadataBuilder alloc] init]; builder.mediator = self.mediationTag; - if ( [serverParameters al_containsValueForKey: @"user_age"] ) - { - builder.userAge = [serverParameters al_numberForKey: @"user_age"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_children"] ) - { - builder.userChildren = [serverParameters al_numberForKey: @"user_children"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_income"] ) - { - builder.userIncome = [serverParameters al_numberForKey: @"user_income"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_education"] ) - { - builder.userEducation = [serverParameters al_stringForKey: @"user_education"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_ethnicity"] ) - { - builder.userEthnicity = [serverParameters al_stringForKey: @"user_ethnicity"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_gender"] ) - { - builder.userGender = [serverParameters al_stringForKey: @"user_gender" ]; - } - - if ( [serverParameters al_containsValueForKey: @"user_marital_status"] ) - { - builder.userMaritalStatus = [serverParameters al_stringForKey: @"user_marital_status"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_politics"] ) - { - builder.userPolitics = [serverParameters al_stringForKey: @"user_politics"]; - } - - if ( [serverParameters al_containsValueForKey: @"dob"] ) - { - NSDate *DOB = [NSDate dateWithTimeIntervalSince1970: [serverParameters al_numberForKey: @"dob"].al_timeIntervalValue]; - builder.userDOB = DOB; - } - - if ( [serverParameters al_containsValueForKey: @"user_state"] ) - { - builder.userState = [serverParameters al_stringForKey: @"user_state"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_country"] ) - { - builder.userCountry = [serverParameters al_stringForKey: @"user_country"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_postal_code"] ) - { - builder.userPostalCode = [serverParameters al_stringForKey: @"user_postal_code"]; - } - - if ( [serverParameters al_containsValueForKey: @"user_dma"] ) + if ( [bidResponse al_isValidString] ) { - builder.userDMA = [serverParameters al_stringForKey: @"user_dma"]; + builder.placementData = @{@"adContent" : bidResponse, + @"overrideWaterfallProvider" : @"waterfallprovider/sideloading"}; } return [builder build]; } -+ (MAAdapterError *)toMaxError:(VASErrorInfo *)verizonAdsError ++ (MAAdapterError *)toMaxError:(YASErrorInfo *)yahooAdsError { - VASCoreError verizonErrorCode = verizonAdsError.code; + YASCoreError verizonErrorCode = yahooAdsError.code; MAAdapterError *adapterError = MAAdapterError.unspecified; switch ( verizonErrorCode ) { - case VASCoreErrorAdNotAvailable: + case YASCoreErrorAdNotAvailable: adapterError = MAAdapterError.noFill; break; - case VASCoreErrorAdFetchFailure: - case VASCoreErrorUnexpectedServerError: - case VASCoreErrorBadServerResponseCode: + case YASCoreErrorAdFetchFailure: + case YASCoreErrorUnexpectedServerError: + case YASCoreErrorBadServerResponseCode: adapterError = MAAdapterError.serverError; break; - case VASCoreErrorTimeout: + case YASCoreErrorTimeout: adapterError = MAAdapterError.timeout; break; - case VASCoreErrorNotImplemented: - case VASCoreErrorAdAdapterNotFound: - case VASCoreErrorAdPrepareFailure: - case VASCoreErrorWaterfallFailure: - case VASCoreErrorBidsNotAvailable: - case VASCoreErrorPluginNotEnabled: - case VASCoreErrorAdFetchFailureApplicationInBackground: - case VASCoreErrorEmptyExchangeServerResponse: + case YASCoreErrorEmptyExchangeServerResponse: + adapterError = MAAdapterError.serverError; + break; + case YASCoreErrorPlacementConfigNotAvailable: + adapterError = MAAdapterError.invalidConfiguration; + break; + case YASCoreErrorSDKNotInitialized: + adapterError = MAAdapterError.notInitialized; + break; + case YASCoreErrorNotImplemented: + case YASCoreErrorAdAdapterNotFound: + case YASCoreErrorAdPrepareFailure: + case YASCoreErrorWaterfallFailure: + case YASCoreErrorPluginNotEnabled: + case YASCoreErrorAdFetchFailureApplicationInBackground: adapterError = MAAdapterError.unspecified; break; } @@ -512,30 +420,30 @@ + (MAAdapterError *)toMaxError:(VASErrorInfo *)verizonAdsError #pragma clang diagnostic ignored "-Wdeprecated-declarations" return [MAAdapterError errorWithCode: adapterError.errorCode errorString: adapterError.errorMessage - thirdPartySdkErrorCode: verizonErrorCode - thirdPartySdkErrorMessage: verizonAdsError.localizedDescription]; + thirdPartySdkErrorCode: yahooAdsError.code + thirdPartySdkErrorMessage: yahooAdsError.localizedDescription]; #pragma clang diagnostic pop } -- (VASInlineAdSize *)adSizeFromAdFormat:(MAAdFormat *)adFormat +- (YASInlineAdSize *)adSizeFromAdFormat:(MAAdFormat *)adFormat { if ( adFormat == MAAdFormat.banner ) { - return [[VASInlineAdSize alloc] initWithWidth: 320 height: 50]; + return [[YASInlineAdSize alloc] initWithWidth: 320 height: 50]; } else if ( adFormat == MAAdFormat.mrec ) { - return [[VASInlineAdSize alloc] initWithWidth: 300 height: 250]; + return [[YASInlineAdSize alloc] initWithWidth: 300 height: 250]; } else if ( adFormat == MAAdFormat.leader ) { - return [[VASInlineAdSize alloc] initWithWidth: 728 height: 90]; + return [[YASInlineAdSize alloc] initWithWidth: 728 height: 90]; } else { [NSException raise: NSInvalidArgumentException format: @"Unsupported ad format: %@", adFormat]; - return [[VASInlineAdSize alloc] initWithWidth: 320 height: 50]; + return [[YASInlineAdSize alloc] initWithWidth: 320 height: 50]; } } @@ -554,7 +462,7 @@ - (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdap return self; } -- (void)interstitialAdFactory:(VASInterstitialAdFactory *)adFactory didLoadInterstitialAd:(VASInterstitialAd *)interstitialAd +- (void)interstitialAdDidLoad:(YASInterstitialAd *)interstitialAd { [self.parentAdapter log: @"Interstitial ad loaded"]; @@ -572,42 +480,42 @@ - (void)interstitialAdFactory:(VASInterstitialAdFactory *)adFactory didLoadInter } } -- (void)interstitialAdFactory:(VASInterstitialAdFactory *)adFactory didFailWithError:(VASErrorInfo *)errorInfo +- (void)interstitialAdLoadDidFail:(YASInterstitialAd *)interstitialAd withError:(YASErrorInfo *)errorInfo { - [self.parentAdapter log: @"Interstitial ad (AdFactory) failed with error: %@", errorInfo.description]; + [self.parentAdapter log: @"Interstitial ad load failed with error: %@", errorInfo.description]; [self.delegate didFailToLoadInterstitialAdWithError: [ALVerizonAdsMediationAdapter toMaxError: errorInfo]]; } -- (void)interstitialAdDidFail:(VASInterstitialAd *)interstitialAd withError:(VASErrorInfo *)errorInfo +- (void)interstitialAdDidFail:(YASInterstitialAd *)interstitialAd withError:(YASErrorInfo *)errorInfo { [self.parentAdapter log: @"Interstitial ad failed with error: %@", errorInfo.description]; [self.delegate didFailToLoadInterstitialAdWithError: [ALVerizonAdsMediationAdapter toMaxError: errorInfo]]; } -- (void)interstitialAdDidShow:(VASInterstitialAd *)interstitialAd +- (void)interstitialAdDidShow:(YASInterstitialAd *)interstitialAd { [self.parentAdapter log: @"Interstitial ad shown"]; [self.delegate didDisplayInterstitialAd]; } -- (void)interstitialAdClicked:(VASInterstitialAd *)interstitialAd +- (void)interstitialAdClicked:(YASInterstitialAd *)interstitialAd { [self.parentAdapter log: @"Interstitial ad clicked"]; [self.delegate didClickInterstitialAd]; } -- (void)interstitialAdDidLeaveApplication:(VASInterstitialAd *)interstitialAd +- (void)interstitialAdDidLeaveApplication:(YASInterstitialAd *)interstitialAd { [self.parentAdapter log: @"Interstitial ad left application"]; } -- (void)interstitialAdDidClose:(VASInterstitialAd *)interstitialAd +- (void)interstitialAdDidClose:(YASInterstitialAd *)interstitialAd { [self.parentAdapter log: @"Interstitial ad closed"]; [self.delegate didHideInterstitialAd]; } -- (void)interstitialAdEvent:(VASInterstitialAd *)interstitialAd source:(NSString *)source eventId:(NSString *)eventId arguments:(NSDictionary *)arguments +- (void)interstitialAdEvent:(YASInterstitialAd *)interstitialAd source:(NSString *)source eventId:(NSString *)eventId arguments:(NSDictionary *)arguments { [self.parentAdapter log: @"Interstitial ad event from source: %@ with event ID: %@ and arguments: %@", source, eventId, arguments]; @@ -632,7 +540,7 @@ - (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdap return self; } -- (void)interstitialAdFactory:(VASInterstitialAdFactory *)adFactory didLoadInterstitialAd:(VASInterstitialAd *)rewardedAd +- (void)interstitialAdDidLoad:(YASInterstitialAd *)rewardedAd { [self.parentAdapter log: @"Rewarded ad loaded"]; @@ -650,19 +558,19 @@ - (void)interstitialAdFactory:(VASInterstitialAdFactory *)adFactory didLoadInter } } -- (void)interstitialAdFactory:(VASInterstitialAdFactory *)adFactory didFailWithError:(VASErrorInfo *)errorInfo +- (void)interstitialAdLoadDidFail:(YASInterstitialAd *)rewardedAd withError:(YASErrorInfo *)errorInfo { - [self.parentAdapter log: @"Rewarded ad (AdFactory) failed with error: %@", errorInfo.description]; + [self.parentAdapter log: @"Rewarded ad load failed with error: %@", errorInfo.description]; [self.delegate didFailToLoadRewardedAdWithError: [ALVerizonAdsMediationAdapter toMaxError: errorInfo]]; } -- (void)interstitialAdDidFail:(VASInterstitialAd *)rewardedAd withError:(VASErrorInfo *)errorInfo +- (void)interstitialAdDidFail:(YASInterstitialAd *)rewardedAd withError:(YASErrorInfo *)errorInfo { [self.parentAdapter log: @"Rewarded ad failed with error: %@", errorInfo.description]; [self.delegate didFailToLoadRewardedAdWithError: [ALVerizonAdsMediationAdapter toMaxError: errorInfo]]; } -- (void)interstitialAdDidShow:(VASInterstitialAd *)rewardedAd +- (void)interstitialAdDidShow:(YASInterstitialAd *)rewardedAd { [self.parentAdapter log: @"Rewarded ad shown"]; @@ -670,18 +578,18 @@ - (void)interstitialAdDidShow:(VASInterstitialAd *)rewardedAd [self.delegate didStartRewardedAdVideo]; } -- (void)interstitialAdClicked:(VASInterstitialAd *)rewardedAd +- (void)interstitialAdClicked:(YASInterstitialAd *)rewardedAd { [self.parentAdapter log: @"Rewarded ad clicked"]; [self.delegate didClickRewardedAd]; } -- (void)interstitialAdDidLeaveApplication:(VASInterstitialAd *)rewardedAd +- (void)interstitialAdDidLeaveApplication:(YASInterstitialAd *)rewardedAd { [self.parentAdapter log: @"Rewarded ad left application"]; } -- (void)interstitialAdDidClose:(VASInterstitialAd *)rewardedAd +- (void)interstitialAdDidClose:(YASInterstitialAd *)rewardedAd { [self.delegate didCompleteRewardedAdVideo]; @@ -696,7 +604,7 @@ - (void)interstitialAdDidClose:(VASInterstitialAd *)rewardedAd [self.delegate didHideRewardedAd]; } -- (void)interstitialAdEvent:(VASInterstitialAd *)rewardedAd source:(NSString *)source eventId:(NSString *)eventId arguments:(NSDictionary *)arguments +- (void)interstitialAdEvent:(YASInterstitialAd *)rewardedAd source:(NSString *)source eventId:(NSString *)eventId arguments:(NSDictionary *)arguments { [self.parentAdapter log: @"Rewarded ad event from source: %@ with event ID: %@ and arguments: %@", source, eventId, arguments]; @@ -730,13 +638,10 @@ - (UIViewController *)inlineAdPresentingViewController return [ALUtils topViewControllerFromKeyWindow]; } -- (void)inlineAdFactory:(VASInlineAdFactory *)adFactory didLoadInlineAd:(VASInlineAdView *)inlineAd +- (void)inlineAdDidLoad:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView loaded"]; - // Disable AdView ad refresh by setting the refresh interval to max value. - inlineAd.refreshInterval = NSUIntegerMax; - self.parentAdapter.inlineAdView = inlineAd; NSString *creativeId = inlineAd.creativeInfo.creativeId; @@ -752,52 +657,52 @@ - (void)inlineAdFactory:(VASInlineAdFactory *)adFactory didLoadInlineAd:(VASInli } } -- (void)inlineAdFactory:(VASInlineAdFactory *)adFactory didFailWithError:(VASErrorInfo *)errorInfo +- (void)inlineAdLoadDidFail:(YASInlineAdView *)inlineAd withError:(YASErrorInfo *)errorInfo { - [self.parentAdapter log: @"AdView (AdFactory) failed to load with error: %@", errorInfo]; + [self.parentAdapter log: @"AdView failed to load with error: %@", errorInfo]; [self.delegate didFailToLoadAdViewAdWithError: [ALVerizonAdsMediationAdapter toMaxError: errorInfo]]; } -- (void)inlineAdDidFail:(VASInlineAdView *)inlineAd withError:(VASErrorInfo *)errorInfo +- (void)inlineAdDidFail:(YASInlineAdView *)inlineAd withError:(YASErrorInfo *)errorInfo { [self.parentAdapter log: @"AdView failed to load with error: %@", errorInfo]; [self.delegate didFailToLoadAdViewAdWithError: [ALVerizonAdsMediationAdapter toMaxError: errorInfo]]; } -- (void)inlineAdClicked:(VASInlineAdView *)inlineAd +- (void)inlineAdClicked:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView clicked"]; [self.delegate didClickAdViewAd]; } -- (void)inlineAdDidLeaveApplication:(VASInlineAdView *)inlineAd +- (void)inlineAdDidLeaveApplication:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView left application"]; } -- (void)inlineAdDidExpand:(VASInlineAdView *)inlineAd +- (void)inlineAdDidExpand:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView expanded"]; [self.delegate didExpandAdViewAd]; } -- (void)inlineAdDidCollapse:(VASInlineAdView *)inlineAd +- (void)inlineAdDidCollapse:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView collapsed"]; [self.delegate didCollapseAdViewAd]; } -- (void)inlineAdDidRefresh:(VASInlineAdView *)inlineAd +- (void)inlineAdDidRefresh:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView refreshed"]; } -- (void)inlineAdDidResize:(VASInlineAdView *)inlineAd +- (void)inlineAdDidResize:(YASInlineAdView *)inlineAd { [self.parentAdapter log: @"AdView resized"]; } -- (void)inlineAd:(VASInlineAdView *)inlineAd event:(NSString *)eventId source:(NSString *)source arguments:(NSDictionary *)arguments +- (void)inlineAd:(YASInlineAdView *)inlineAd event:(NSString *)eventId source:(NSString *)source arguments:(NSDictionary *)arguments { [self.parentAdapter log: @"AdView event from source: %@ with event ID: %@ and arguments: %@", source, eventId, arguments]; @@ -825,120 +730,122 @@ - (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdap return self; } -- (void)nativeAdFactory:(VASNativeAdFactory *)adFactory didLoadNativeAd:(VASNativeAd *)nativeAd +- (void)nativeAdDidLoad:(YASNativeAd *)nativeAd { - [self.parentAdapter log: @"Native ad loaded: %@", nativeAd.placementId]; - dispatchOnMainQueue(^{ - id titleComponent = (id)[nativeAd component: @"title"]; - id disclaimerComponent = (id)[nativeAd component: @"disclaimer"]; - id bodyComponent = (id)[nativeAd component: @"body"]; - id ctaComponent = (id)[nativeAd component: @"callToAction"]; - id iconComponent = (id)[nativeAd component: @"iconImage"]; - id mediaImageComponent = (id)[nativeAd component: @"mainImage"]; - id mediaVideoComponent = (id)[nativeAd component: @"video"]; + [self.parentAdapter log: @"Native ad loaded: %@", nativeAd.placementId]; + + NSString *title = ((id)[nativeAd component: @"title"]).text; + NSString *body = ((id)[nativeAd component: @"body"]).text; + NSString *advertiser = ((id)[nativeAd component: @"disclaimer"]).text; + NSString *callToAction = ((id)[nativeAd component: @"callToAction"]).text; + + MANativeAdImage *iconImage; + id iconImageComponent = (id)[self.parentAdapter.nativeAd component: @"iconImage"]; + if ( iconImageComponent ) + { + UIImageView *iconImageView = [[UIImageView alloc] init]; + iconImageView.contentMode = UIViewContentModeScaleAspectFit; + [iconImageComponent prepareView: iconImageView]; + + // NOTE: Yahoo's SDK only returns UIImageView with the image pre-cached, we cannot use the 'URL' property + // since it is un-cached and our SDK will attempt to re-cache it, and we do not support passing UIImageView for custom native + iconImage = [[MANativeAdImage alloc] initWithImage: iconImageView.image]; + } UIView *mediaView; CGFloat mediaContentAspectRatio = 0.0f; - if ( mediaVideoComponent.view ) + id videoComponent = (id)[nativeAd component: @"video"]; + id mainImageComponent = (id)[nativeAd component: @"mainImage"]; + + // If video is available, use that + if ( videoComponent ) { - mediaView = mediaVideoComponent.view; - mediaContentAspectRatio = mediaVideoComponent.width / mediaVideoComponent.height; + mediaContentAspectRatio = videoComponent.width / videoComponent.height; + + mediaView = [[YASYahooVideoPlayerView alloc] init]; + [videoComponent prepareView: (YASVideoPlayerView *) mediaView]; } - else if ( mediaImageComponent.view ) + else if ( mainImageComponent ) { - mediaView = mediaImageComponent.view; - mediaContentAspectRatio = mediaImageComponent.width / mediaImageComponent.height; + mediaContentAspectRatio = mainImageComponent.width / mainImageComponent.height; + + mediaView = [[UIImageView alloc] init]; + mediaView.contentMode = UIViewContentModeScaleAspectFit; + [mainImageComponent prepareView: (UIImageView *) mediaView]; } - mediaView.contentMode = UIViewContentModeScaleAspectFit; - NSString *templateName = [self.serverParameters al_stringForKey: @"template" defaultValue: @""]; BOOL isTemplateAd = [templateName al_isValidString]; - if ( isTemplateAd && ![titleComponent.text al_isValidString] ) + if ( isTemplateAd && ![title al_isValidString] ) { - [self.parentAdapter e: @"Custom native ad (%@) does not have required assets.", nativeAd]; - [self.delegate didFailToLoadNativeAdWithError: [MAAdapterError errorWithCode: -5400 errorString: @"Missing Native Ad Assets"]]; + [self.parentAdapter e: @"Native ad (%@) does not have required assets.", nativeAd]; + [self.delegate didFailToLoadNativeAdWithError: + [MAAdapterError errorWithCode: -5400 errorString: @"Missing Native Ad Assets"] + ]; return; } self.parentAdapter.nativeAd = nativeAd; - dispatch_group_t group = dispatch_group_create(); - __block MANativeAdImage *iconImage = nil; - if ( iconComponent.URL ) - { - [self.parentAdapter log: @"Fetching native ad icon: %@", iconComponent.URL]; - [self loadImageForURLString: iconComponent.URL.absoluteString group: group successHandler:^(UIImage *image) { - iconImage = [[MANativeAdImage alloc] initWithImage: image]; - }]; - } - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + MANativeAd *maxNativeAd = [[MAVerizonNativeAd alloc] initWithParentAdapter: self.parentAdapter + builderBlock:^(MANativeAdBuilder *builder) { + builder.title = title; + builder.body = body; + builder.advertiser = advertiser; + builder.callToAction = callToAction; + builder.icon = iconImage; + builder.mediaView = mediaView; - // Timeout tasks if incomplete within the given time - dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kDefaultImageTaskTimeoutSeconds * NSEC_PER_SEC))); - - MANativeAd *maxNativeAd = [[MAVerizonNativeAd alloc] initWithParentAdapter: self.parentAdapter - andNotify: self.delegate - builderBlock:^(MANativeAdBuilder *builder) { - builder.title = titleComponent.text; - builder.advertiser = disclaimerComponent.text; - builder.body = bodyComponent.text; - builder.callToAction = ctaComponent.text; - builder.icon = iconImage; - builder.mediaView = mediaView; - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" - // Introduced in 11.4.0 - if ( [builder respondsToSelector: @selector(setMediaContentAspectRatio:)] ) - { - [builder performSelector: @selector(setMediaContentAspectRatio:) withObject: @(mediaContentAspectRatio)]; - } + // Introduced in 11.4.0 + if ( [builder respondsToSelector: @selector(setMediaContentAspectRatio:)] ) + { + [builder performSelector: @selector(setMediaContentAspectRatio:) withObject: @(mediaContentAspectRatio)]; + } #pragma clang diagnostic pop - }]; - - VASCreativeInfo *creativeInfo = nativeAd.creativeInfo; - NSDictionary *extraInfo = [creativeInfo.creativeId al_isValidString] ? @{@"creative_id" : creativeInfo.creativeId} : nil; - - [self.delegate didLoadAdForNativeAd: maxNativeAd withExtraInfo: extraInfo]; - }); + }]; + + YASCreativeInfo *creativeInfo = nativeAd.creativeInfo; + NSDictionary *extraInfo = [creativeInfo.creativeId al_isValidString] ? @{@"creative_id" : creativeInfo.creativeId} : nil; + + [self.delegate didLoadAdForNativeAd: maxNativeAd withExtraInfo: extraInfo]; }); } -- (void)nativeAdFactory:(VASNativeAdFactory *)adFactory didFailWithError:(VASErrorInfo *)errorInfo +- (void)nativeAdLoadDidFail:(YASNativeAd *)nativeAd withError:(YASErrorInfo *)errorInfo { MAAdapterError *adapterError = [ALVerizonAdsMediationAdapter toMaxError: errorInfo]; - [self.parentAdapter log: @"Native ad factory (%@) failed to load with error: %@", adFactory.placementId, adapterError]; + [self.parentAdapter log: @"Native ad (%@) failed to load with error: %@", nativeAd.placementId, adapterError]; [self.delegate didFailToLoadNativeAdWithError: adapterError]; } -- (void)nativeAdDidFail:(VASNativeAd *)nativeAd withError:(VASErrorInfo *)errorInfo +- (void)nativeAdDidFail:(YASNativeAd *)nativeAd withError:(YASErrorInfo *)errorInfo { MAAdapterError *adapterError = [ALVerizonAdsMediationAdapter toMaxError: errorInfo]; [self.parentAdapter log: @"Native ad (%@) failed to load with error: %@", nativeAd.placementId, adapterError]; [self.delegate didFailToLoadNativeAdWithError: adapterError]; } -- (void)nativeAdClicked:(VASNativeAd *)nativeAd withComponent:(id)component +- (void)nativeAdClicked:(YASNativeAd *)nativeAd withComponent:(id)component { [self.parentAdapter log: @"Native ad clicked"]; [self.delegate didClickNativeAd]; } -- (void)nativeAdDidLeaveApplication:(VASNativeAd *)nativeAd +- (void)nativeAdDidLeaveApplication:(YASNativeAd *)nativeAd { [self.parentAdapter log: @"Native ad left application"]; } -- (void)nativeAdDidClose:(VASNativeAd *)nativeAd +- (void)nativeAdDidClose:(YASNativeAd *)nativeAd { [self.parentAdapter log: @"Native ad closed"]; } -- (void)nativeAd:(VASNativeAd *)nativeAd event:(NSString *)eventId source:(NSString *)source arguments:(NSDictionary *)arguments +- (void)nativeAd:(YASNativeAd *)nativeAd event:(NSString *)eventId source:(NSString *)source arguments:(NSDictionary *)arguments { [self.parentAdapter log: @"Native event from source: %@ with event ID: %@ and arguments: %@", source, eventId, arguments]; @@ -953,53 +860,21 @@ - (UIViewController *)nativeAdPresentingViewController return [ALUtils topViewControllerFromKeyWindow]; } -- (void)loadImageForURLString:(NSString *)urlString group:(dispatch_group_t)group successHandler:(void (^)(UIImage *image))successHandler; -{ - dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ - - dispatch_group_enter(group); - - [[[NSURLSession sharedSession] dataTaskWithURL: [NSURL URLWithString: urlString] - completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - if ( error ) - { - [self.parentAdapter log: @"Failed to fetch native ad image with error: %@", error]; - } - else if ( data ) - { - [self.parentAdapter log: @"Native ad image data retrieved"]; - - UIImage *image = [UIImage imageWithData: data]; - if ( image ) - { - successHandler(image); - } - } - - // Don't consider the block done until this task is complete - dispatch_group_leave(group); - }] resume]; - }); -} - @end @implementation MAVerizonNativeAd -- (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdapter - andNotify:(id)delegate - builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock +- (instancetype)initWithParentAdapter:(ALVerizonAdsMediationAdapter *)parentAdapter builderBlock:(NS_NOESCAPE MANativeAdBuilderBlock)builderBlock { self = [super initWithFormat: MAAdFormat.native builderBlock: builderBlock]; if ( self ) { self.parentAdapter = parentAdapter; - self.delegate = delegate; } return self; } -- (void)prepareViewForInteraction:(MANativeAdView *)nativeAdView +- (void)prepareViewForInteraction:(MANativeAdView *)maxNativeAdView { if ( !self.parentAdapter.nativeAd ) { @@ -1007,30 +882,7 @@ - (void)prepareViewForInteraction:(MANativeAdView *)nativeAdView return; } - // Verizon's click registration methods don't work with views when recycling is involved - // so they told us to manually invoke it as AdMob does - dispatchOnMainQueue(^{ - - self.parentAdapter.titleGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickAction)]; - self.parentAdapter.advertiserGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickAction)]; - self.parentAdapter.bodyGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickAction)]; - self.parentAdapter.iconGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickAction)]; - self.parentAdapter.ctaGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(clickAction)]; - - [nativeAdView.titleLabel addGestureRecognizer: self.parentAdapter.titleGestureRecognizer]; - [nativeAdView.advertiserLabel addGestureRecognizer: self.parentAdapter.advertiserGestureRecognizer]; - [nativeAdView.bodyLabel addGestureRecognizer: self.parentAdapter.bodyGestureRecognizer]; - [nativeAdView.iconImageView addGestureRecognizer: self.parentAdapter.iconGestureRecognizer]; - [nativeAdView.callToActionButton addGestureRecognizer: self.parentAdapter.ctaGestureRecognizer]; - }); -} - -- (void)clickAction -{ - [self.parentAdapter log: @"Native ad clicked from gesture recognizer"]; - - [self.parentAdapter.nativeAd invokeDefaultAction]; - [self.delegate didClickNativeAd]; + [self.parentAdapter.nativeAd registerContainerView: maxNativeAdView]; } @end