diff options
-rw-r--r-- | iphone/Maps/Core/Ads/Banner.swift | 1 | ||||
-rw-r--r-- | iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift | 4 | ||||
-rw-r--r-- | iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h | 1 | ||||
-rw-r--r-- | iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.mm | 19 | ||||
-rw-r--r-- | iphone/Maps/Core/Ads/Mopub/MopubBanner.swift | 4 | ||||
-rw-r--r-- | iphone/Maps/Core/Ads/RB/RBBanner.swift | 4 | ||||
-rw-r--r-- | iphone/Maps/UI/Ads/AdBanner.swift | 22 |
7 files changed, 45 insertions, 10 deletions
diff --git a/iphone/Maps/Core/Ads/Banner.swift b/iphone/Maps/Core/Ads/Banner.swift index 666ed13359..06e2ebd111 100644 --- a/iphone/Maps/Core/Ads/Banner.swift +++ b/iphone/Maps/Core/Ads/Banner.swift @@ -5,6 +5,7 @@ protocol Banner: MWMBanner { typealias Failure = (BannerType, EventName, ErrorDetails, NSError) -> Void typealias Click = (Banner) -> Void func reload(success: @escaping Success, failure: @escaping Failure, click: @escaping Click) + func unregister() var isBannerOnScreen: Bool { get set } var isNeedToRetain: Bool { get } diff --git a/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift b/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift index 9ef62fa2a2..9d4eba9b49 100644 --- a/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift +++ b/iphone/Maps/Core/Ads/Facebook/FacebookBanner.swift @@ -15,6 +15,10 @@ final class FacebookBanner: FBNativeAd, Banner { requestDate = Date() } + func unregister() { + unregisterView() + } + var isPossibleToReload: Bool { if let date = requestDate { return Date().timeIntervalSince(date) > Limits.minTimeSinceLastRequest diff --git a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h index 29ee5a99ba..ee378884a1 100644 --- a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h +++ b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.h @@ -4,5 +4,6 @@ @interface MPNativeAd (MWM) <MPNativeViewDelegate> - (void)setAdView:(UIView *)view actionButtons:(NSArray<UIButton *> *)buttons; +- (void)unregister; @end diff --git a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.mm b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.mm index 44428d0ed5..69076c90db 100644 --- a/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.mm +++ b/iphone/Maps/Core/Ads/Mopub/MPNativeAd+MWM.mm @@ -28,9 +28,10 @@ self.associatedView = static_cast<MPNativeView *>(view); static_cast<MWMAdBanner *>(view).mpNativeAd = self; if (!self.hasAttachedToView) { - if ([self.adAdapter isKindOfClass:[FacebookNativeAdAdapter class]]) + auto adapter = self.adAdapter; + if ([adapter isKindOfClass:[FacebookNativeAdAdapter class]]) { - auto fbAdapter = static_cast<FacebookNativeAdAdapter *>(self.adAdapter); + auto fbAdapter = static_cast<FacebookNativeAdAdapter *>(adapter); [fbAdapter.fbNativeAd registerViewForInteraction:self.associatedView withViewController:[self viewControllerForPresentingModalView] withClickableViews:buttons]; @@ -49,4 +50,18 @@ } } +- (void)unregister +{ + auto adapter = self.adAdapter; + self.delegate = nil; + [self nativeViewWillMoveToSuperview:nil]; + self.associatedView = nil; + self.hasAttachedToView = NO; + if ([adapter isKindOfClass:[FacebookNativeAdAdapter class]]) + { + auto fbAdapter = static_cast<FacebookNativeAdAdapter *>(adapter); + [fbAdapter.fbNativeAd unregisterView]; + } +} + @end diff --git a/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift b/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift index 5e118cc41f..b49c4046d3 100644 --- a/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift +++ b/iphone/Maps/Core/Ads/Mopub/MopubBanner.swift @@ -22,6 +22,10 @@ final class MopubBanner: NSObject, Banner { requestDate = Date() } + func unregister() { + nativeAd?.unregister() + } + var isBannerOnScreen = false { didSet { if isBannerOnScreen { diff --git a/iphone/Maps/Core/Ads/RB/RBBanner.swift b/iphone/Maps/Core/Ads/RB/RBBanner.swift index 1d7ac717fa..025d925420 100644 --- a/iphone/Maps/Core/Ads/RB/RBBanner.swift +++ b/iphone/Maps/Core/Ads/RB/RBBanner.swift @@ -86,6 +86,10 @@ final class RBBanner: MTRGNativeAd, Banner { requestDate = Date() } + func unregister() { + unregisterView() + } + var isBannerOnScreen = false { didSet { if isBannerOnScreen { diff --git a/iphone/Maps/UI/Ads/AdBanner.swift b/iphone/Maps/UI/Ads/AdBanner.swift index 2b215ce11d..4f730da2be 100644 --- a/iphone/Maps/UI/Ads/AdBanner.swift +++ b/iphone/Maps/UI/Ads/AdBanner.swift @@ -45,7 +45,14 @@ final class AdBanner: UITableViewCell { var state = AdBannerState.unset { didSet { - guard state != .unset else { return } + guard state != .unset else { + adPrivacyButton.isHidden = true + adCallToActionButtonCustom.isHidden = true + mpNativeAd = nil + nativeAd = nil + return + } + guard state != oldValue else { return } let config = state.config() adTitleLabel.numberOfLines = config.numberOfTitleLines adBodyLabel.numberOfLines = config.numberOfBodyLines @@ -65,7 +72,11 @@ final class AdBanner: UITableViewCell { adIconImageView.af_cancelImageRequest() } - private var nativeAd: MWMBanner? + private var nativeAd: Banner? { + willSet { + nativeAd?.unregister() + } + } @IBAction private func privacyAction() { @@ -76,8 +87,6 @@ final class AdBanner: UITableViewCell { func reset() { state = .unset - adPrivacyButton.isHidden = true - adCallToActionButtonCustom.isHidden = true } func config(ad: MWMBanner, containerType: AdBannerContainerType) { @@ -89,7 +98,7 @@ final class AdBanner: UITableViewCell { state = .search } - nativeAd = ad + nativeAd = ad as? Banner switch ad.mwmType { case .none: assert(false) @@ -125,7 +134,6 @@ final class AdBanner: UITableViewCell { } private func configFBBanner(ad: FBNativeAd) { - ad.unregisterView() let adCallToActionButtons: [UIView] if (state == .search) { adCallToActionButtons = [self] @@ -154,8 +162,6 @@ final class AdBanner: UITableViewCell { } private func configRBBanner(ad: MTRGNativeAd) { - ad.unregisterView() - guard let banner = ad.banner else { return } ad.loadIcon(to: adIconImageView) |