gpt4 book ai didi

ios - 谷歌分析与 Swift 3 iOS 9

转载 作者:行者123 更新时间:2023-12-02 01:08:57 25 4
gpt4 key购买 nike

我尝试查找有关如何将 Google Analytics 与 Swift 3 结合使用的信息,即使看起来有些人成功了,但我自己却无法使其发挥作用。

Google Analytics 文档没有帮助,它仅适用于 Swift 2。

我在版本 3.17.0 中使用了 pod“Google/Analytics”,并尝试在桥接头文件中添加这一行,正如一些人提到的:

#import <Google/Analytics.h>

但是我收到了一个关于 Xcode 的错误,提示桥接 header 不适用于 Swift 3。

然后我尝试按照另一篇文章的建议在 .h 中添加相同的行,但两者都不起作用,Xcode 提示“在框架模块 XXX 中包含非模块化 header ”。

我尝试将“允许框架模块中的非模块化包含”设置为"is",但它没有改变任何内容,仍然出现相同的错误。

我尝试的最后一件事是添加:

import Google

在我使用 Google Analytics 的文件内,但现在无法识别 GAI。

// Configure tracker from GoogleService-Info.plist.
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")

// Optional: configure GAI options.
guard let gai = GAI.sharedInstance() else {
assert(false, "Google Analytics not configured correctly")
}
gai.trackUncaughtExceptions = true // report uncaught exceptions
gai.logger.logLevel = GAILogLevel.verbose // remove before app release

有什么建议吗?

最佳答案

请按照以下步骤配置 Google Analytics(分析)

  1. 在 Google Analytics 上创建一个项目并下载配置文件“GoogleService-Info.plist”
  2. 使用 Pod 将 Google Analytics 安装到您的项目(确保终端中显示错误)
  3. 清除并关闭您的项目,然后导航到您的项目文件夹并打开“XXX.xcworkspace”而不是“XXX.xcodeproj”。
  4. 然后将“GoogleService-Info.plist”添加到您的项目中(选中“如果需要则复制”选项)。
  5. 在您的项目中创建一个桥接文件(如果已经存在),则无需重新创建它。

    5.1。要创建桥接文件,最简单的方法是向项目添加/创建新的 Objective-C 类,然后会弹出一个选项,要求您创建桥接文件,并默认设置所有设置。

  6. 打开通常名为“YourProjectName-Bridging-Header.h”的桥接文件并将其复制到其中 " #import <Google/Analytics.h> "
  7. 打开“AppDelegate.swift”并将以下代码复制并粘贴到didFinishLaunchingWithOptions中以设置 Analytics 跟踪器

    // Configure tracker from GoogleService-Info.plist.
    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

    // Optional: configure GAI options.
    guard let gai = GAI.sharedInstance() else {
    assert(false, "Google Analytics not configured correctly")
    }
    gai.trackUncaughtExceptions = true // report uncaught exceptions
    gai.logger.logLevel = GAILogLevel.verbose // remove before app release
  8. 构建您的项目。

我希望它能正常工作,如果有任何问题请告诉我。

关于ios - 谷歌分析与 Swift 3 iOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41781754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com