From f0332a58cebb733d262e149a0c7d06509e269428 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Wed, 29 Jan 2020 18:40:18 +0300 Subject: [PATCH] [iOS] Fixed Banners with new mopub --- iphone/Maps/Classes/MapsAppDelegate.mm | 8 ++++++++ iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift | 3 +-- iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h | 2 ++ iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.m | 7 +++++-- iphone/Maps/Core/Ads/Mopub/MopubBanner.swift | 13 ++++++++----- iphone/Maps/Podfile | 2 +- iphone/Maps/Podfile.lock | 4 ++-- iphone/Maps/Pods/Manifest.lock | 4 ++-- iphone/Maps/UI/Ads/AdBanner.swift | 14 ++++++++------ .../AuthorizationViewController.swift | 5 ++--- 10 files changed, 39 insertions(+), 23 deletions(-) diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 23b149bcaf..f3fb7fdcca 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -37,6 +37,7 @@ #include "platform/http_thread_apple.h" #include "platform/local_country_file_utils.hpp" +#include "partners_api/mopub_ads.hpp" #include "base/assert.hpp" @@ -267,6 +268,13 @@ using namespace osm_auth_ios; }]; } + MPMoPubConfiguration *sdkConfig = [[MPMoPubConfiguration alloc] initWithAdUnitIdForAppInitialization:@(ads::Mopub::InitializationBannerId().c_str())]; + NSDictionary * facebookConfig = @{@"native_banner" : @true}; + NSMutableDictionary * config = [@{@"FacebookAdapterConfiguration" : facebookConfig} mutableCopy]; + sdkConfig.mediatedNetworkConfigurations = config; + sdkConfig.loggingLevel = MPBLogLevelDebug; + [[MoPub sharedInstance] initializeSdkWithConfiguration:sdkConfig completion:nil]; + if ([MoPubKit shouldShowConsentDialog]) [MoPubKit grantConsent]; diff --git a/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift b/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift index b68c068611..3f8cd49819 100644 --- a/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift +++ b/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift @@ -19,7 +19,7 @@ final class FacebookBanner: NSObject, Banner { self.failure = failure self.click = click - nativeAd.load() + nativeAd.loadAd(withMediaCachePolicy: .all) requestDate = Date() } @@ -88,7 +88,6 @@ final class FacebookBanner: NSObject, Banner { init(bannerID: String) { nativeAd = FBNativeAd(placementID: bannerID) - nativeAd.mediaCachePolicy = .all super.init() nativeAd.delegate = self let center = NotificationCenter.default diff --git a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h index 5d59abb9cf..9a6dff2341 100644 --- a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h +++ b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h @@ -2,6 +2,8 @@ #import "MPNativeAd.h" #import "MPNativeView.h" +@class FBNativeAd; + @interface MPNativeAd (MWM) - (void)setAdView:(UIView *)view actionButtons:(NSArray *)buttons; diff --git a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.m b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.m index 492af050ed..aee705f551 100644 --- a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.m +++ b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.m @@ -1,5 +1,6 @@ #import "MPNativeAd+MWM.h" #import "SwiftBridge.h" +#import @interface MPNativeAd () @@ -26,8 +27,10 @@ { FacebookNativeAdAdapter *fbAdapter = (FacebookNativeAdAdapter *)adapter; [fbAdapter.fbNativeAd registerViewForInteraction:self.associatedView - withViewController:[self viewControllerForPresentingModalView] - withClickableViews:buttons]; + mediaView:[[FBMediaView alloc] init] + iconView:Nil + viewController:[self viewControllerForPresentingModalView] + clickableViews:buttons]; } else { diff --git a/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift b/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift index 036dcc5a5b..d272176f54 100644 --- a/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift +++ b/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift @@ -1,3 +1,5 @@ +import MoPub_FacebookAudienceNetwork_Adapters + final class MopubBanner: NSObject, Banner { private enum Limits { static let minTimeOnScreen: TimeInterval = 3 @@ -138,7 +140,7 @@ final class MopubBanner: NSObject, Banner { return (nativeAd.adAdapter as! FacebookNativeAdAdapter).fbNativeAd.adChoicesLinkURL } - return URL(string: kDAAIconTapDestinationURL) + return URL(string: kPrivacyIconTapDestinationURL) } // MARK: - Helpers @@ -147,12 +149,13 @@ final class MopubBanner: NSObject, Banner { private func load() { let settings = MPStaticNativeAdRendererSettings() let config = MPStaticNativeAdRenderer.rendererConfiguration(with: settings)! - request = MPNativeAdRequest(adUnitIdentifier: placementID, rendererConfigurations: [config]) + let fbConfig = FacebookNativeAdRenderer.rendererConfiguration(with: settings) + request = MPNativeAdRequest(adUnitIdentifier: placementID, rendererConfigurations: [config, fbConfig]) let targeting = MPNativeAdRequestTargeting() - targeting.keywords = "user_lang:\(AppInfo.shared().twoLetterLanguageId ?? "")" - targeting.desiredAssets = [kAdTitleKey, kAdTextKey, kAdIconImageKey, kAdCTATextKey] + targeting?.keywords = "user_lang:\(AppInfo.shared().twoLetterLanguageId ?? "")" + targeting?.desiredAssets = [kAdTitleKey, kAdTextKey, kAdIconImageKey, kAdCTATextKey] if let location = MWMLocationManager.lastLocation() { - targeting.location = location + targeting?.location = location } request.targeting = targeting diff --git a/iphone/Maps/Podfile b/iphone/Maps/Podfile index e4a7e968aa..293edddf0c 100644 --- a/iphone/Maps/Podfile +++ b/iphone/Maps/Podfile @@ -14,7 +14,7 @@ pod 'ActionSheetPicker-3.0', '2.3.0' pod 'FBSDKCoreKit', '5.15' pod 'FBSDKLoginKit', '5.15' pod 'Flurry-iOS-SDK/FlurrySDK', '10.1' -pod 'mopub-ios-sdk', '~> 5.10' +pod 'mopub-ios-sdk', '5.10' pod 'MoPub-FacebookAudienceNetwork-Adapters', '5.6.0.0' end diff --git a/iphone/Maps/Podfile.lock b/iphone/Maps/Podfile.lock index 8247a869e4..8e84a9e301 100644 --- a/iphone/Maps/Podfile.lock +++ b/iphone/Maps/Podfile.lock @@ -44,7 +44,7 @@ DEPENDENCIES: - FBSDKLoginKit (= 5.15) - Flurry-iOS-SDK/FlurrySDK (= 10.1) - MoPub-FacebookAudienceNetwork-Adapters (= 5.6.0.0) - - mopub-ios-sdk (~> 5.10) + - mopub-ios-sdk (= 5.10) - Pushwoosh (= 5.16.0) SPEC REPOS: @@ -70,6 +70,6 @@ SPEC CHECKSUMS: mopub-ios-sdk: 3d65133b95b6498aa871a66818a11a5ba307e565 Pushwoosh: 6cba171e52f3f7b8ccd280f492a5831deac2f594 -PODFILE CHECKSUM: 68054a76d0d74219f643b4055fca97f6fcdcf5d1 +PODFILE CHECKSUM: 733b86434976d4702689274a81b45cdafc689454 COCOAPODS: 1.8.3 diff --git a/iphone/Maps/Pods/Manifest.lock b/iphone/Maps/Pods/Manifest.lock index 8247a869e4..8e84a9e301 100644 --- a/iphone/Maps/Pods/Manifest.lock +++ b/iphone/Maps/Pods/Manifest.lock @@ -44,7 +44,7 @@ DEPENDENCIES: - FBSDKLoginKit (= 5.15) - Flurry-iOS-SDK/FlurrySDK (= 10.1) - MoPub-FacebookAudienceNetwork-Adapters (= 5.6.0.0) - - mopub-ios-sdk (~> 5.10) + - mopub-ios-sdk (= 5.10) - Pushwoosh (= 5.16.0) SPEC REPOS: @@ -70,6 +70,6 @@ SPEC CHECKSUMS: mopub-ios-sdk: 3d65133b95b6498aa871a66818a11a5ba307e565 Pushwoosh: 6cba171e52f3f7b8ccd280f492a5831deac2f594 -PODFILE CHECKSUM: 68054a76d0d74219f643b4055fca97f6fcdcf5d1 +PODFILE CHECKSUM: 733b86434976d4702689274a81b45cdafc689454 COCOAPODS: 1.8.3 diff --git a/iphone/Maps/UI/Ads/AdBanner.swift b/iphone/Maps/UI/Ads/AdBanner.swift index 686a2c9f6a..80cd916ba0 100644 --- a/iphone/Maps/UI/Ads/AdBanner.swift +++ b/iphone/Maps/UI/Ads/AdBanner.swift @@ -1,4 +1,5 @@ import FBAudienceNetwork +import MoPub_FacebookAudienceNetwork_Adapters private func attributedTitle(title: String, indent: CGFloat) -> NSAttributedString { let paragraphStyle = NSMutableParagraphStyle() @@ -157,14 +158,15 @@ final class AdBanner: UITableViewCell { } else { adCallToActionButtons = [adCallToActionButtonCompact, adCallToActionButtonDetailed] } - ad.registerView(forInteraction: self, with: nil, withClickableViews: adCallToActionButtons) + ad.registerView(forInteraction: self, + mediaView: FBMediaView(), + iconImageView: adIconImageView, + viewController: UIViewController.topViewController(), + clickableViews: adCallToActionButtons) - ad.icon?.loadAsync { [weak self] image in - self?.adIconImageView.image = image - } - adTitleLabel.attributedText = attributedTitle(title: ad.title ?? "", + adTitleLabel.attributedText = attributedTitle(title: ad.headline ?? "", indent: adPrivacyImage.width + DAAImageWidth.constant) - adBodyLabel.text = ad.body ?? "" + adBodyLabel.text = ad.bodyText ?? "" let config = state.config() adTitleLabel.numberOfLines = config.numberOfTitleLines adBodyLabel.numberOfLines = config.numberOfBodyLines diff --git a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift index a9f402840d..b562e30914 100644 --- a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift +++ b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift @@ -91,9 +91,8 @@ final class AuthorizationViewController: MWMViewController { } @IBAction func facebookSignIn() { - let fbLoginManager = FBSDKLoginManager() - fbLoginManager.loginBehavior = .systemAccount - fbLoginManager.logIn(withReadPermissions: ["public_profile", "email"], from: self) { [weak self] (result, error) in + let fbLoginManager = LoginManager() + fbLoginManager.logIn(permissions: ["public_profile", "email"], from: self) { [weak self] (result, error) in if let error = error { self?.process(error: error, type: .facebook) } else if let token = result?.token {