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 ...@@ -16,12 +16,24 @@ import Flurry_iOS_SDK
public class AdManager { public class AdManager {
private var lastSetA9AppKey: String?
private var lastSetMoPubAppKey: String?
private var lastSetUseGeolocation: Bool?
public static let shared: AdManager = AdManager() public static let shared: AdManager = AdManager()
public func start(a9AppKey: String, mopubAppKey: String, useGeolocation: Bool) { public func start(a9AppKey: String, mopubAppKey: String, useGeolocation: Bool) {
guard !self.initialized else { guard !self.initialized else {
return 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) AdLogger.setDebugMode(Settings.shared.adLogging)
...@@ -49,10 +61,9 @@ public class AdManager { ...@@ -49,10 +61,9 @@ public class AdManager {
private func initializeMoPub(initializationAdUnitId: String) { private func initializeMoPub(initializationAdUnitId: String) {
let moPubConfig = MPMoPubConfiguration(adUnitIdForAppInitialization: initializationAdUnitId) //any valid placement from the app can be used let moPubConfig = MPMoPubConfiguration(adUnitIdForAppInitialization: initializationAdUnitId) //any valid placement from the app can be used
moPubConfig.loggingLevel = AdLogger.debugMode ? MPBLogLevel.debug : MPBLogLevel.none moPubConfig.loggingLevel = AdLogger.debugMode ? MPBLogLevel.debug : MPBLogLevel.none
moPubConfig.allowLegitimateInterest = true // moPubConfig.allowLegitimateInterest = true
moPubConfig.additionalNetworks = nil moPubConfig.additionalNetworks = nil
MoPub.sharedInstance().initializeSdk(with: moPubConfig) { [weak self] in MoPub.sharedInstance().initializeSdk(with: moPubConfig) { [weak self] in
...@@ -73,7 +84,8 @@ public class AdManager { ...@@ -73,7 +84,8 @@ public class AdManager {
} }
private init() { 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 { deinit {
...@@ -143,9 +155,22 @@ public class AdManager { ...@@ -143,9 +155,22 @@ public class AdManager {
return topViewController return topViewController
} }
@objc private func environmentChanged() { @objc
private func environmentChanged() {
updateAmazonTestMode(for: EnvironmentManager.shared.environment) 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) { private func updateAmazonTestMode(for environment: Environment) {
DTBAds.sharedInstance().testMode = environment == Environment.test DTBAds.sharedInstance().testMode = environment == Environment.test
......
...@@ -156,7 +156,6 @@ public class WdtWeatherSource: WeatherSource { ...@@ -156,7 +156,6 @@ public class WdtWeatherSource: WeatherSource {
let locationResponse = try decoder.decode(WdtHealth.self, from: data) let locationResponse = try decoder.decode(WdtHealth.self, from: data)
var newLocation = location var newLocation = location
newLocation.today?.uv = locationResponse.uvIndex?.today 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) completion(newLocation, nil)
} }
catch { catch {
......
...@@ -50,19 +50,17 @@ class TodayViewModel: ViewModelProtocol { ...@@ -50,19 +50,17 @@ class TodayViewModel: ViewModelProtocol {
locationManager.updateEverythingIfNeeded() locationManager.updateEverythingIfNeeded()
} }
private var adsInitialized = false
private func initializeAllAdsIfNeeded() { private func initializeAllAdsIfNeeded() {
onMain { onMain {
guard !self.adsInitialized else { return } let adManager = AdManager.shared
self.adsInitialized = true guard !adManager.initialized else { return }
CCPAHelper.shared.updateCCPAStatus(reason: "initialization") CCPAHelper.shared.updateCCPAStatus(reason: "initialization")
if !isAppPro() { if !isAppPro() {
// In Debug mode we allow the user to change the environment // In Debug mode we allow the user to change the environment
//TODO AdStack: add MoPub App Key //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 // Location SDK setup
let canCollectData = CCPAHelper.shared.canCollectData ?? false 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