forked from organicmaps/organicmaps
[iOS] Fixed Banners with new mopub
This commit is contained in:
parent
e60b45759b
commit
f0332a58ce
10 changed files with 39 additions and 23 deletions
|
@ -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];
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#import "MPNativeAd.h"
|
||||
#import "MPNativeView.h"
|
||||
|
||||
@class FBNativeAd;
|
||||
|
||||
@interface MPNativeAd (MWM) <MPNativeViewDelegate>
|
||||
|
||||
- (void)setAdView:(UIView *)view actionButtons:(NSArray<UIButton *> *)buttons;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import "MPNativeAd+MWM.h"
|
||||
#import "SwiftBridge.h"
|
||||
#import <FBAudienceNetwork/FBNativeAd.h>
|
||||
|
||||
@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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
4
iphone/Maps/Pods/Manifest.lock
generated
4
iphone/Maps/Pods/Manifest.lock
generated
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue