diff --git a/Podfile b/Podfile index c6d5efa87fcd..c3047244de94 100644 --- a/Podfile +++ b/Podfile @@ -50,7 +50,7 @@ def wordpress_ui end def wordpress_kit - pod 'WordPressKit', '~> 8.5.0-beta.3' + pod 'WordPressKit', '~> 8.5-beta.3' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '' diff --git a/Podfile.lock b/Podfile.lock index e7387b5bcede..2e989e6cd297 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -612,7 +612,7 @@ DEPENDENCIES: - SwiftLint (~> 0.50) - WordPress-Editor-iOS (~> 1.19.8) - WordPressAuthenticator (~> 6.1-beta) - - WordPressKit (~> 8.5.0-beta.3) + - WordPressKit (~> 8.5-beta.3) - WordPressShared (~> 2.2-beta) - WordPressUI (~> 1.12.5) - WPMediaPicker (~> 1.8-beta) @@ -895,6 +895,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: 7be6a8ed524025ed4acf2454718cab08a0b9e310 +PODFILE CHECKSUM: 66f009c76957bfeaeeb56fd48cb877edb372951c COCOAPODS: 1.12.1 diff --git a/WordPress/Classes/ViewRelated/EEUUSCompliance/ComplianceLocationService.swift b/WordPress/Classes/ViewRelated/EEUUSCompliance/ComplianceLocationService.swift index a5f2cd4350a9..78abee732725 100644 --- a/WordPress/Classes/ViewRelated/EEUUSCompliance/ComplianceLocationService.swift +++ b/WordPress/Classes/ViewRelated/EEUUSCompliance/ComplianceLocationService.swift @@ -2,13 +2,6 @@ import WordPressKit final class ComplianceLocationService { func getIPCountryCode(completion: @escaping (Result) -> Void) { - IPLocationRemote().fetchIPCountryCode { result in - switch result { - case .success(let countryCode): - completion(.success(countryCode)) - case .failure(let error): - completion(.failure(error)) - } - } + IPLocationRemote().fetchIPCountryCode(completion: completion) } } diff --git a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopover.swift b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopover.swift index bf6bae402498..6c1a2380e457 100644 --- a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopover.swift +++ b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopover.swift @@ -111,10 +111,7 @@ private enum Strings { static let subtitle = NSLocalizedString( "compliance.analytics.popover.subtitle", - value: """ - We process your personal data to optimize our website and - marketing activities based on your consent and our legitimate interest. - """, + value: "We process your personal data to optimize our website and marketing activities based on your consent and our legitimate interest.", comment: "Subtitle for the privacy compliance popover." ) @@ -126,10 +123,7 @@ private enum Strings { static let footnote = NSLocalizedString( "compliance.analytics.popover.footnote", - value: """ - These cookies allow us to optimize performance by collecting - information on how users interact with our websites. - """, + value: "These cookies allow us to optimize performance by collecting information on how users interact with our websites.", comment: "Footnote for the privacy compliance popover." ) diff --git a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverCoordinator.swift b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverCoordinator.swift index 35aa430957bc..c452386ddf31 100644 --- a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverCoordinator.swift +++ b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverCoordinator.swift @@ -1,9 +1,6 @@ import UIKit final class CompliancePopoverCoordinator { - fileprivate enum Constants { - static let shouldShowCompliancePopup = "shouldShowCompliancePopup" - } private let viewController: UIViewController private let complianceService = ComplianceLocationService() @@ -19,28 +16,20 @@ final class CompliancePopoverCoordinator { return } complianceService.getIPCountryCode { [weak self] result in - switch result { - case .success(let countryCode): + if case .success(let countryCode) = result { guard let self, self.shouldShowPrivacyBanner(countryCode: countryCode) else { return } DispatchQueue.main.async { - let complianceViewModel = CompliancePopoverViewModel(defaults: self.defaults) - complianceViewModel.coordinator = self - let complianceViewController = CompliancePopoverViewController(viewModel: complianceViewModel) - let bottomSheetViewController = BottomSheetViewController(childViewController: complianceViewController, customHeaderSpacing: 0) - - bottomSheetViewController.show(from: self.viewController) + self.presentPopover() } - case .failure(let error): - () } } } func shouldShowPrivacyBanner(countryCode: String) -> Bool { let isCountryInEU = Self.gdprCountryCodes.contains(countryCode) - return isCountryInEU && defaults.shouldShowCompliancePopup + return isCountryInEU && !defaults.didShowCompliancePopup } func navigateToSettings() { @@ -52,6 +41,15 @@ final class CompliancePopoverCoordinator { func dismiss() { viewController.dismiss(animated: true) } + + private func presentPopover() { + let complianceViewModel = CompliancePopoverViewModel(defaults: self.defaults) + complianceViewModel.coordinator = self + let complianceViewController = CompliancePopoverViewController(viewModel: complianceViewModel) + let bottomSheetViewController = BottomSheetViewController(childViewController: complianceViewController, customHeaderSpacing: 0) + + bottomSheetViewController.show(from: self.viewController) + } } private extension CompliancePopoverCoordinator { @@ -94,11 +92,13 @@ private extension CompliancePopoverCoordinator { } extension UserDefaults { - @objc dynamic var shouldShowCompliancePopup: Bool { + static let didShowCompliancePopupKey = "didShowCompliancePopup" + + @objc var didShowCompliancePopup: Bool { get { - bool(forKey: CompliancePopoverCoordinator.Constants.shouldShowCompliancePopup) + bool(forKey: Self.didShowCompliancePopupKey) } set { - set(newValue, forKey: CompliancePopoverCoordinator.Constants.shouldShowCompliancePopup) + set(newValue, forKey: Self.didShowCompliancePopupKey) } } } diff --git a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewController.swift b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewController.swift index 005b0a9f229a..9a43c70eacd6 100644 --- a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewController.swift +++ b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewController.swift @@ -5,11 +5,7 @@ import WordPressUI final class CompliancePopoverViewController: UIViewController { // MARK: - Views - private lazy var hostingController: UIHostingController = { - let controller = UIHostingController(rootView: CompliancePopover(viewModel: self.viewModel)) - controller.view.translatesAutoresizingMaskIntoConstraints = true - return controller - }() + private let hostingController: UIHostingController private var contentView: UIView { return hostingController.view @@ -20,6 +16,7 @@ final class CompliancePopoverViewController: UIViewController { init(viewModel: CompliancePopoverViewModel) { self.viewModel = viewModel + hostingController = UIHostingController(rootView: CompliancePopover(viewModel: self.viewModel)) super.init(nibName: nil, bundle: nil) } @@ -31,6 +28,7 @@ final class CompliancePopoverViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.addContentView() + hostingController.view.translatesAutoresizingMaskIntoConstraints = true hostingController.rootView.goToSettingsAction = { self.viewModel.didTapSettings() } @@ -46,10 +44,8 @@ final class CompliancePopoverViewController: UIViewController { self.contentView.frame = .init(origin: .zero, size: contentViewSize) self.preferredContentSize = contentView.bounds.size - DispatchQueue.main.async { - self.hostingController.rootView.screenHeight = self.view.frame.height - self.hostingController.rootView.shouldScroll = (contentViewSize.height + 100) > self.view.frame.height - } + self.hostingController.rootView.screenHeight = self.view.frame.height + self.hostingController.rootView.shouldScroll = (contentViewSize.height + 100) > self.view.frame.height } private func addContentView() { diff --git a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewModel.swift b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewModel.swift index 3f7839a7d573..e87a688e3120 100644 --- a/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewModel.swift +++ b/WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewModel.swift @@ -15,25 +15,25 @@ final class CompliancePopoverViewModel: ObservableObject { func didTapSettings() { coordinator?.navigateToSettings() - defaults.shouldShowCompliancePopup = false + defaults.didShowCompliancePopup = true } func didTapSave() { let appAnalytics = WordPressAppDelegate.shared?.analytics appAnalytics?.setUserHasOptedOut(!isAnalyticsEnabled) - let account = ContextManager.shared.performQuery { context -> WPAccount? in + let (accountID, restAPI) = ContextManager.shared.performQuery { context -> (NSNumber?, WordPressComRestApi?) in let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context) - return account + return (account?.userID, account?.wordPressComRestApi) } - guard let account else { + guard let accountID, let restAPI else { return } let change = AccountSettingsChange.tracksOptOut(!isAnalyticsEnabled) - AccountSettingsService(userID: account.userID.intValue, api: account.wordPressComRestApi).saveChange(change) + AccountSettingsService(userID: accountID.intValue, api: restAPI).saveChange(change) coordinator?.dismiss() - defaults.shouldShowCompliancePopup = false + defaults.didShowCompliancePopup = true } }