Commit 2810cc64 by Demid Merzlyakov

Show privacy notice.

parent d30f7f87
......@@ -10,3 +10,6 @@ import Foundation
let kMoEngageAppId = "11PSBEC6K93IYU1AC8WIYADY"
let kEventInAppPurchasedCompleted = "EventInAppPurchasedCompleted"
let a9AppKey = "2e440b094f7c44b4bae7044b764c61ac"
let kAdMoPubInitializationAdUnitId = "05bff78d4a4245bd98ff6b595c134889"
let kOLAppMetricsKey: String = "OLAppMetricsKey"
......@@ -31,7 +31,7 @@ class CCPAHelper {
setCCPAStatusForThirdParties()
locationPermissionsUndeterminedOnLaunch = CLLocationManager.authorizationStatus() == .notDetermined
//TODO: it's better to move this to a background thread, but we need to make sure it won't break locations array initialization inside of the WeatherUpdateManager.
hadLocationsOnLaunch = !LocationManager.shared.locations.isEmpty
hadLocationsOnLaunch = LocationManager.shared.hasLocations
log.debug("CCPA Helper: isNewUser: \(isNewUser ? "true" : "false")")
}
......
......@@ -188,6 +188,10 @@ public class LocationManager {
}
}
public var hasLocations: Bool {
!locations.isEmpty || deviceLocationMonitor.hasLocationPermissions
}
public init(weatherUpdateSource: WeatherSource, healthSource: HealthSource, nwsAlertsManager: NWSAlertsManager, fipsSource: FIPSSource, pushNotificationsManager: PushNotificationsManager, storage: Storage) {
self.weatherUpdateSource = weatherUpdateSource
self.healthSource = healthSource
......
......@@ -26,6 +26,12 @@
"notifications.nwsCell.remainsInEffectUntil" = "remains in effect until";
"notifications.nwsAlert.forecastOffice" = "Forecast office";
//Today
"privacy.notice.title" = "Privacy notice";
"privacy.notice.text" = "You can modify your choices at any time as per our Privacy Policy, and use this app without sharing your location. We utilise location data to deliver forecasts, weather alerts & ads. We may share your data with trusted partners to provide you these services.";
"privacy.notice.close" = "Close";
//Forecast
"forecast.sunny" = "Sunny";
"forecast.cloudy" = "Cloudy";
......
......@@ -21,6 +21,14 @@ let BLANK = "--"
let UP_ARROW = "\u{2191}"
let DOWN_ARROW = "\u{2193}"
// isPro
func isAppPro() -> Bool {
if let metricsLog = UserDefaults.standard.dictionary(forKey: kOLAppMetricsKey), let event = metricsLog[kEventInAppPurchasedCompleted] {
return event != nil
}
return false
}
func windUnits() -> WindUnits {
return .mps
}
......
......@@ -47,7 +47,7 @@ class TodayViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.showOnboardingIfNeeded()
viewModel.showOnboardingOrPrivacyNoticeIfNeeded()
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
......@@ -144,6 +144,15 @@ extension TodayViewController: UITableViewDelegate {
//MARK:- ViewModel Delegate
extension TodayViewController: TodayViewModelDelegate {
func showPrivacyNotice(viewModel: TodayViewModel) {
let alertController = UIAlertController(title: "privacy.notice.title".localized(), message: "privacy.notice.text".localized(), preferredStyle: .alert)
let closeAction = UIAlertAction(title: "privacy.notice.close".localized(), style: .cancel) { (_) in
viewModel.privacyPolicyHasBeenViewed()
}
alertController.addAction(closeAction)
self.present(alertController, animated: true, completion: nil)
}
func showOnboarding(viewModel: TodayViewModel) {
coordinator.openOnboarding()
}
......@@ -159,7 +168,7 @@ extension TodayViewController: TodayViewModelDelegate {
// MARK: - TodayCoordinatorDelegate
extension TodayViewController: TodayCoordinatorDelegate {
func childCoordinatorDidFinish(in coordinator: TodayCoordinator) {
viewModel.showOnboardingIfNeeded()
viewModel.showOnboardingOrPrivacyNoticeIfNeeded()
}
}
......@@ -6,9 +6,11 @@
//
import UIKit
import PSMLocationSDK
protocol TodayViewModelDelegate: ViewModelDelegate {
func showOnboarding(viewModel: TodayViewModel)
func showPrivacyNotice(viewModel: TodayViewModel)
}
class TodayViewModel: ViewModelProtocol {
......@@ -38,11 +40,53 @@ class TodayViewModel: ViewModelProtocol {
locationManager.updateEverythingIfNeeded()
}
public func showOnboardingIfNeeded() {
locationManager.doAfterLocationLoad { (locations) in
if locations.count == 0 {
private var adsInitialized = false
private func initializeAllAdsIfNeeded() {
DispatchQueue.main.async {
guard !self.adsInitialized else { return }
self.adsInitialized = true
CCPAHelper.shared.updateCCPAStatus(reason: "initialization")
if !isAppPro() {
// In Debug mode we allow the user to change the environment
//TODO AdStack: add MoPub App Key
AdManager.shared.start(a9AppKey: a9AppKey, mopubAppKey: kAdMoPubInitializationAdUnitId, useGeolocation: true)
// Location SDK setup
let canCollectData = CCPAHelper.shared.canCollectData ?? false
PSMLocation.start(withIdentifier: "OneWeatheriosCfg3", halted: !canCollectData)
print("PSM Location SDK version \(PSMLocation.sdkVersion())")
PSMLocation.sharedInstance().powerSaveMode = true
}
}
}
public func privacyPolicyHasBeenViewed() {
initializeAllAdsIfNeeded()
}
public func showOnboardingOrPrivacyNoticeIfNeeded() {
locationManager.doAfterLocationLoad { [weak self] (locations) in
guard let self = self else { return }
if !self.locationManager.hasLocations {
self.delegate?.showOnboarding(viewModel: self)
}
else {
let ccpaHelper = CCPAHelper.shared
if !ccpaHelper.shownPrivacyNoticeBefore {
if ccpaHelper.policyHasBeenUpdated {
analytics(log: .ANALYTICS_PRIVACY_POLICY_UPDATED)
}
self.delegate?.showPrivacyNotice(viewModel: self)
ccpaHelper.shownPrivacyNoticeBefore = true
}
else {
self.initializeAllAdsIfNeeded()
}
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment