Integrate Umeng analytics and APM

This commit is contained in:
2026-07-07 14:20:04 +08:00
parent 9899a2ccb3
commit 6bdabadc3b
9 changed files with 155 additions and 2 deletions

View File

@ -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 {
}

View 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)
}
}
}

View 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"
}

View File

@ -25,6 +25,7 @@ enum AuthSessionHelper {
if privacyAgreementAccepted {
AMapBootstrap.configureIfNeeded()
UmengBootstrap.configureIfNeeded()
}
NotificationCenter.default.post(name: NotificationName.userDidLogin, object: nil)

View File

@ -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