首页 > 解决方案 > Google Analytics iOS SDK 导致内存泄漏

问题描述

我正在使用通过 Cocoapods 安装的 Google Analytics iOS SDK v3.17.0。当应用程序打开时,我调试内存图。图中可见 32 个内存泄漏。如果我不初始化 Google Analytics,我不会在相同的情况下看到任何泄漏。

我搜索了下面的帖子,但没有包含特定问题并修复

https://github.com/firebase/quickstart-ios/issues/239

Google Analytics 发送命中时的内存泄漏

我如何初始化:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    //Window Properties
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()

    try! initGoogleAnalyticsManager()
    let splashController = SplashViewController()

    self.window?.rootViewController = splashController

    return true
}

 func initGoogleAnalyticsManager() throws{
    guard let gai = GAI.sharedInstance() else {
        assertionFailure("Google Analytics not configured correctly")
        throw ServiceError.createCustomError(title: "Google Analytics Error", message: "Google Analytics Ayarlanamadı", type: ServiceError.ErrorType.ServiceError)
    }
    guard let trackingId = some value else {
        assertionFailure("Google Analytics not configured correctly")
        throw ServiceError.createCustomError(title: "Google Analytics Error", message: "Google Analytics Trackin ID Problem", type: ServiceError.ErrorType.ServiceError)
    }
    gai.tracker(withTrackingId: trackingId)
    // Optional: automatically report uncaught exceptions.
    gai.trackUncaughtExceptions = true

    // Optional: set Logger to VERBOSE for debug information.
    // Remove before app release.
    #if DEBUG
    gai.logger.logLevel = .verbose
    #else
    gai.logger.logLevel = .none
    #endif
}

在此处输入图像描述

标签: iosswiftgoogle-analytics

解决方案


推荐阅读