Commit e340a1da by Demid Merzlyakov

Ads are no longer initialized if they are disabled via the config.

parent df86084c
......@@ -16,12 +16,24 @@ import Flurry_iOS_SDK
public class AdManager {
private var lastSetA9AppKey: String?
private var lastSetMoPubAppKey: String?
private var lastSetUseGeolocation: Bool?
public static let shared: AdManager = AdManager()
public func start(a9AppKey: String, mopubAppKey: String, useGeolocation: Bool) {
guard !self.initialized else {
return
}
self.lastSetA9AppKey = a9AppKey
self.lastSetMoPubAppKey = mopubAppKey
self.lastSetUseGeolocation = useGeolocation
guard AdConfigManager.shared.adConfig.adsEnabled else {
NSLog("psm_ad AdManager [INFO]: not initializing ads, because ads are disabled.")
return
}
AdLogger.setDebugMode(Settings.shared.adLogging)
......@@ -49,10 +61,9 @@ public class AdManager {
private func initializeMoPub(initializationAdUnitId: String) {
let moPubConfig = MPMoPubConfiguration(adUnitIdForAppInitialization: initializationAdUnitId) //any valid placement from the app can be used
moPubConfig.loggingLevel = AdLogger.debugMode ? MPBLogLevel.debug : MPBLogLevel.none
moPubConfig.allowLegitimateInterest = true
// moPubConfig.allowLegitimateInterest = true
moPubConfig.additionalNetworks = nil
MoPub.sharedInstance().initializeSdk(with: moPubConfig) { [weak self] in
......@@ -73,7 +84,8 @@ public class AdManager {
}
private init() {
notificationCenter.addObserver(self, selector: #selector(AdManager.environmentChanged), name: .AdsEnvironmentChanged, object: nil)
notificationCenter.addObserver(self, selector: #selector(environmentChanged), name: .AdsEnvironmentChanged, object: nil)
notificationCenter.addObserver(self, selector: #selector(configChanged), name: .adConfigChanged, object: nil)
}
deinit {
......@@ -143,9 +155,22 @@ public class AdManager {
return topViewController
}
@objc private func environmentChanged() {
@objc
private func environmentChanged() {
updateAmazonTestMode(for: EnvironmentManager.shared.environment)
}
@objc
private func configChanged() {
guard !self.initialized && AdConfigManager.shared.adConfig.adsEnabled else {
return
}
guard let a9Key = lastSetA9AppKey, let mopubKey = lastSetMoPubAppKey, let useGeo = lastSetUseGeolocation else {
return
}
self.start(a9AppKey: a9Key, mopubAppKey: mopubKey, useGeolocation: useGeo)
}
private func updateAmazonTestMode(for environment: Environment) {
DTBAds.sharedInstance().testMode = environment == Environment.test
......
......@@ -156,7 +156,6 @@ public class WdtWeatherSource: WeatherSource {
let locationResponse = try decoder.decode(WdtHealth.self, from: data)
var newLocation = location
newLocation.today?.uv = locationResponse.uvIndex?.today
self.log.debug("DMA Set UV to \(locationResponse.uvIndex?.today ?? -1) Value after setting: \(newLocation.today?.uv ?? -1)")
completion(newLocation, nil)
}
catch {
......
......@@ -50,19 +50,17 @@ class TodayViewModel: ViewModelProtocol {
locationManager.updateEverythingIfNeeded()
}
private var adsInitialized = false
private func initializeAllAdsIfNeeded() {
onMain {
guard !self.adsInitialized else { return }
self.adsInitialized = true
let adManager = AdManager.shared
guard !adManager.initialized else { return }
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)
adManager.start(a9AppKey: a9AppKey, mopubAppKey: kAdMoPubInitializationAdUnitId, useGeolocation: true)
// Location SDK setup
let canCollectData = CCPAHelper.shared.canCollectData ?? false
......
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