Commit 4be57610 by Shailesh Aher

[IOS-127]: Disable tercept SDK if disabled from server

parent 10ba965f
......@@ -214,6 +214,7 @@
CEEB3549266F5DA900E16F90 /* MRECAdCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEB3548266F5DA900E16F90 /* MRECAdCell.swift */; };
CEEF4100265E47FF00425D8F /* BlendFIPSSource.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEEF40FF265E47FF00425D8F /* BlendFIPSSource.framework */; };
CEEF4101265E47FF00425D8F /* BlendFIPSSource.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CEEF40FF265E47FF00425D8F /* BlendFIPSSource.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F227B22E26B2A45700DD7EBB /* AppInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = F227B22D26B2A45700DD7EBB /* AppInfo.swift */; };
F2D8A6E2269D88D10060F36A /* libTerceptSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F2D8A6B9269D88D10060F36A /* libTerceptSDK.a */; };
F2D8A6E3269D88D10060F36A /* x86_64-apple-ios-simulator.swiftinterface in Resources */ = {isa = PBXBuildFile; fileRef = F2D8A6BB269D88D10060F36A /* x86_64-apple-ios-simulator.swiftinterface */; };
F2D8A6E4269D88D10060F36A /* arm64-apple-ios.swiftinterface in Resources */ = {isa = PBXBuildFile; fileRef = F2D8A6BC269D88D10060F36A /* arm64-apple-ios.swiftinterface */; };
......@@ -509,6 +510,7 @@
CEEB3548266F5DA900E16F90 /* MRECAdCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MRECAdCell.swift; sourceTree = "<group>"; };
CEEF40FF265E47FF00425D8F /* BlendFIPSSource.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BlendFIPSSource.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DF826CF4702D9DCCB9A9DD71 /* Pods-1Weather.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.release.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.release.xcconfig"; sourceTree = "<group>"; };
F227B22D26B2A45700DD7EBB /* AppInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfo.swift; sourceTree = "<group>"; };
F2D8A6B7269D88D10060F36A /* PublicHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicHeader.h; sourceTree = "<group>"; };
F2D8A6B8269D88D10060F36A /* TerceptSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TerceptSDK.h; sourceTree = "<group>"; };
F2D8A6B9269D88D10060F36A /* libTerceptSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libTerceptSDK.a; sourceTree = "<group>"; };
......@@ -1304,6 +1306,7 @@
children = (
CDA5542C25EF7C9700A2E08C /* ReusableCellProtocol.swift */,
CD37D404260DFFDD002669D6 /* CellFactory.swift */,
F227B22D26B2A45700DD7EBB /* AppInfo.swift */,
);
path = Common;
sourceTree = "<group>";
......@@ -1944,6 +1947,7 @@
CD85797526721DE500CC4CDA /* UITabBarController+Append.swift in Sources */,
CDDCD50726809F6D00E089AD /* ShortsSwipeHelperView.swift in Sources */,
CD85797D267221AC00CC4CDA /* UITabBarController+Hide.swift in Sources */,
F227B22E26B2A45700DD7EBB /* AppInfo.swift in Sources */,
CDC6126625E9085600188DA7 /* GraphLine.swift in Sources */,
CE13B819262480B3007CBD4D /* A9Cache.swift in Sources */,
CE578FE625FB415F00E8B85D /* LocationViewController.swift in Sources */,
......
//
// AppInfo.swift
// 1Weather
//
// Created by Shailesh on 29/07/21.
//
import UIKit
import AdSupport
struct AppInfo {
static let idfa: String? = ASIdentifierManager.shared().advertisingIdentifier.uuidString
static let idfv: String? = UIDevice.current.identifierForVendor?.uuidString
static var appVersion: String = {
let appInfoDict = Bundle.main.infoDictionary
let appVersion: String = (appInfoDict?["CFBundleShortVersionString"] as? String) ?? "Unknown"
let buildNumber: String = (appInfoDict?[kCFBundleVersionKey as String] as? String) ?? ""
return "\(appVersion)(\(buildNumber))"
}()
}
......@@ -15,5 +15,7 @@
&quot;a9_refresh_rate&quot;: 0,
&quot;placements&quot;: {}
}</string>
<key>ios_terceptsdk_enabled</key>
<false/>
</dict>
</plist>
......@@ -356,7 +356,7 @@ class CCPAHelper {
//MARK: - Models
struct CCPAInitialConsent: Encodable, CustomDebugStringConvertible {
private struct CCPAInitialConsent: Encodable, CustomDebugStringConvertible {
var id: String = ""
var advertisingId = ""
var appVersion = ""
......
......@@ -21,8 +21,9 @@ public struct AppConfig: Codable {
public let shortsLeftBelowCount: Int
public let shortsLastNudgeEnabled: Bool
public let shortsSwipeUpNudgeCount: Int
public let terceptSDKTrackingEnabled: Bool
public init(popularCities: [GeoNamesPlace]?, adConfig: AdConfig, ccpaUpdateInterval: TimeInterval?, nwsAlertsViaMoEngageEnabled: Bool, showAttPrompt: Bool, shortsLeftBelowCountKey: Int, shortsLastNudgeEnabledKey: Bool, shortsSwipeUpNudgeCountKey: Int) {
public init(popularCities: [GeoNamesPlace]?, adConfig: AdConfig, ccpaUpdateInterval: TimeInterval?, nwsAlertsViaMoEngageEnabled: Bool, showAttPrompt: Bool, shortsLeftBelowCountKey: Int, shortsLastNudgeEnabledKey: Bool, shortsSwipeUpNudgeCountKey: Int, terceptSDKTrackingEnabled: Bool) {
self.popularCities = popularCities
self.adConfig = adConfig
self.ccpaUpdateInterval = ccpaUpdateInterval
......@@ -31,6 +32,7 @@ public struct AppConfig: Codable {
self.shortsLeftBelowCount = shortsLeftBelowCountKey
self.shortsLastNudgeEnabled = shortsLastNudgeEnabledKey
self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey
self.terceptSDKTrackingEnabled = terceptSDKTrackingEnabled
}
}
......@@ -47,6 +49,7 @@ public class ConfigManager {
private static let shortsLeftBelowCountKey = "shorts_left_below_nudge_every_x_cards"
private static let shortsLastNudgeEnabledKey = "shorts_swipe_down_nudge_enabled"
private static let shortsSwipeUpNudgeCountKey = "shorts_swipe_up_nudge_on_x_cards"
private static let terceptSDKTrackingEnabled = "ios_terceptsdk_enabled"
private let delegates = MulticastDelegate<ConfigManagerDelegate>()
......@@ -69,7 +72,8 @@ public class ConfigManager {
showAttPrompt: false,
shortsLeftBelowCountKey: 0,
shortsLastNudgeEnabledKey: false,
shortsSwipeUpNudgeCountKey: 0)
shortsSwipeUpNudgeCountKey: 0,
terceptSDKTrackingEnabled: false)
public func updateConfig() {
log.info("update config")
......@@ -152,6 +156,9 @@ public class ConfigManager {
let shortsSwipeNudgeCountValue = remoteConfig.configValue(forKey: ConfigManager.shortsSwipeUpNudgeCountKey)
let shortsSwipeNudgeCount = shortsSwipeNudgeCountValue.numberValue.intValue
let terceptSDKTrackingEnabledValue = remoteConfig.configValue(forKey: ConfigManager.terceptSDKTrackingEnabled)
let terceptSDKTrackingEnabled = terceptSDKTrackingEnabledValue.boolValue
DispatchQueue.main.async {
self.config = AppConfig(popularCities: popularCities,
adConfig: adConfig,
......@@ -160,7 +167,8 @@ public class ConfigManager {
showAttPrompt: showAttPrompt,
shortsLeftBelowCountKey: shortsLeftBelowCount,
shortsLastNudgeEnabledKey: shortsLastNudgeEnabled,
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount)
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount,
terceptSDKTrackingEnabled: terceptSDKTrackingEnabled)
self.notifyAboutConfigUpdate()
DispatchQueue.global().async {
let encoder = JSONEncoder()
......
......@@ -23,39 +23,35 @@ protocol AdEventLoggable {
extension TerceptOptimization: TerceptOpimizable { }
final class TerceptSDKManager: AdEventLoggable, DependencyRepresentable {
private let optimizable: TerceptOpimizable
private var optimizer: TerceptOpimizable?
private struct Constants {
static let DFPCode: String = "120348554"
static var IDFA: String {
CCPAInitialConsent.getInstance().advertisingId
}
static var IDFV: String {
CCPAInitialConsent.getInstance().id
}
static var version: String {
CCPAInitialConsent.getInstance().appVersion
}
static var IDFA: String { AppInfo.idfa ?? "UNKNOWN" }
static var IDFV: String { AppInfo.idfv ?? "UNKNOWN" }
static var version: String { AppInfo.appVersion }
}
required init() {
optimizable = TerceptOptimization(Constants.DFPCode)
updateKeys()
registerNotifications()
fetchIfAvailable()
}
init(optimizable: TerceptOpimizable = TerceptOptimization(Constants.DFPCode), adUnitIDs: [String]) {
self.optimizable = optimizable
init(optimizable: TerceptOpimizable, adUnitIDs: [String]) {
self.optimizer = optimizable
updateKeys()
optimizable.fetch(adUnitIDs)
registerNotifications()
fetchIfAvailable()
}
private func initializeSDK() {
optimizer = TerceptOptimization(Constants.DFPCode)
updateKeys()
fetchIfAvailable()
}
private func updateKeys() {
optimizable.initParams(Constants.IDFA, Constants.IDFV, ["appVersion": Constants.version])
optimizer?.initParams(Constants.IDFA, Constants.IDFV, ["appVersion": Constants.version])
}
private func registerNotifications() {
......@@ -67,6 +63,7 @@ final class TerceptSDKManager: AdEventLoggable, DependencyRepresentable {
selector: #selector(fetchIfAvailable),
name: .adConfigChanged,
object: nil)
ConfigManager.shared.add(delegate: self)
}
@objc private func fetchIfAvailable() {
......@@ -77,25 +74,33 @@ final class TerceptSDKManager: AdEventLoggable, DependencyRepresentable {
}
private func register(adUnitIDs: [String]) {
optimizable.fetch(adUnitIDs)
optimizer?.fetch(adUnitIDs)
}
func getTracker(with adUnitId: String) -> TerceptAdTracker {
return TerceptAdTracker(adUnitId: adUnitId,
logger: self,
customKeys: optimizable.getCustomTargetingKeys(adUnitId))
customKeys: optimizer?.getCustomTargetingKeys(adUnitId) ?? [:])
}
func setCustomParameters(_ params: [String : String]) {
optimizable.setCustomParameters(params)
optimizer?.setCustomParameters(params)
}
@discardableResult func logEvent(_ adunit: String?, _ event: String?, _ customParams: [String : Any]) -> Bool {
return optimizable.logEvent(adunit, event, customParams)
return optimizer?.logEvent(adunit, event, customParams) ?? false
}
@objc private func handleSwitchToBackground() {
optimizable.sendEventsData()
optimizer?.sendEventsData()
}
}
extension TerceptSDKManager: ConfigManagerDelegate {
func dataUpdated(by configManager: ConfigManager) {
if configManager.config.terceptSDKTrackingEnabled {
initializeSDK()
}
}
}
......
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