Integrate Umeng analytics and APM
This commit is contained in:
@ -13,6 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
UmengBootstrap.configureIfNeeded()
|
||||
if AppStore.shared.privacyAgreementAccepted, !AppStore.shared.token.isEmpty {
|
||||
AMapBootstrap.configureIfNeeded()
|
||||
}
|
||||
@ -35,4 +36,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
51
suixinkan/Config/UmengBootstrap.swift
Normal file
51
suixinkan/Config/UmengBootstrap.swift
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
15
suixinkan/Config/UmengConfig.swift
Normal file
15
suixinkan/Config/UmengConfig.swift
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// UmengConfig.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 友盟统计与性能监控 SDK 配置。
|
||||
enum UmengConfig {
|
||||
/// 友盟后台申请的 iOS AppKey。
|
||||
nonisolated static let appKey = "6a470b81cbfa6959516c34d0"
|
||||
|
||||
/// 友盟渠道标识,默认使用官方 App Store 渠道。
|
||||
nonisolated static let channel = "App Store"
|
||||
}
|
||||
@ -25,6 +25,7 @@ enum AuthSessionHelper {
|
||||
|
||||
if privacyAgreementAccepted {
|
||||
AMapBootstrap.configureIfNeeded()
|
||||
UmengBootstrap.configureIfNeeded()
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: NotificationName.userDidLogin, object: nil)
|
||||
|
||||
@ -7,3 +7,10 @@
|
||||
#import <AMapLocationKit/AMapLocationKit.h>
|
||||
#import <MAMapKit/MAMapKit.h>
|
||||
#import <AMapSearchKit/AMapSearchKit.h>
|
||||
#import <UMCommon/UMCommon.h>
|
||||
|
||||
#if __has_include(<UMAPM/UMAPM.h>)
|
||||
#import <UMAPM/UMAPM.h>
|
||||
#elif __has_include(<UMAPM/UMCrashConfigure.h>)
|
||||
#import <UMAPM/UMCrashConfigure.h>
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user