Files
suixinkan_uikit/suixinkan/Config/UmengBootstrap.swift

52 lines
1.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UmengBootstrap.swift
// suixinkan
//
import Foundation
/// SDK
enum UmengBootstrap {
/// SDK
private(set) static var isConfigured = false
private static let lock = NSLock()
private static var configureHandler: (_ appKey: String, _ channel: String) -> Void = { appKey, channel in
UMConfigure.setLogEnabled(false)
UMConfigure.initWithAppkey(appKey, channel: channel)
}
/// App SDK
@discardableResult
static func configureIfNeeded(appStore: AppStore = .shared) -> Bool {
guard appStore.privacyAgreementAccepted else { return false }
lock.lock()
defer { lock.unlock() }
guard !isConfigured else { return true }
configureHandler(UmengConfig.appKey, UmengConfig.channel)
isConfigured = true
return true
}
/// SDK
static func setConfigureHandlerForTesting(_ handler: @escaping (_ appKey: String, _ channel: String) -> Void) {
lock.lock()
defer { lock.unlock() }
configureHandler = handler
}
///
static func resetForTesting() {
lock.lock()
defer { lock.unlock() }
isConfigured = false
configureHandler = { appKey, channel in
UMConfigure.setLogEnabled(false)
UMConfigure.initWithAppkey(appKey, channel: channel)
}
}
}