Files
suixinkan_uikit/suixinkan/Features/Location/AMapBootstrap.swift

50 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.

//
// AMapBootstrap.swift
// suixinkan
//
import Foundation
/// SDK Key SDK
enum AMapBootstrap {
private(set) static var isConfigured = false
private static let lock = NSLock()
/// 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 }
AMapLocationManager.updatePrivacyShow(.didShow, privacyInfo: .didContain)
AMapLocationManager.updatePrivacyAgree(.didAgree)
MAMapView.updatePrivacyShow(.didShow, privacyInfo: .didContain)
MAMapView.updatePrivacyAgree(.didAgree)
AMapSearchAPI.updatePrivacyShow(.didShow, privacyInfo: .didContain)
AMapSearchAPI.updatePrivacyAgree(.didAgree)
AMapServices.shared().apiKey = AMapConfig.apiKey
AMapServices.shared().enableHTTPS = true
isConfigured = true
return true
}
/// SDK
static func requireConfigured(appStore: AppStore = .shared) throws {
guard configureIfNeeded(appStore: appStore) else {
throw LocationProviderError.privacyNotAccepted
}
}
///
static func resetForTesting() {
lock.lock()
defer { lock.unlock() }
isConfigured = false
}
}