gpt4 book ai didi

firebase - 将 Firebase 分析与 SwiftUI 结合使用

转载 作者:行者123 更新时间:2023-12-04 16:25:17 26 4
gpt4 key购买 nike

我最近在我的 SwiftUI 应用中安装了 Firebase Analytics。除了自动屏幕 View 外,一切都很好。我是否有义务为要跟踪的每个 View 调用 AnalyticsEventScreenView?

最佳答案

是的 - 由于 SwiftUI View 的结构方式,Analytics 只能看到 NotifyingMulticolumnSplitViewController .
您必须手动发送屏幕 View (如 stated in the docs ),如下所示:

import SwiftUI
import Firebase

struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: OneView()) {
Text("One")
}
NavigationLink(destination: TwoView()) {
Text("Two")
}
}
.navigationTitle("Choose a screen")
.onAppear() {
Analytics.logEvent(AnalyticsEventScreenView,
parameters: [AnalyticsParameterScreenName: "\(ContentView.self)",
AnalyticsParameterScreenClass: "\(ContentView.self)"])
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
import SwiftUI
import Firebase

struct OneView: View {
var body: some View {
Text("1")
.onAppear() {
Analytics.logEvent(AnalyticsEventScreenView,
parameters: [AnalyticsParameterScreenName: "\(OneView.self)",
AnalyticsParameterScreenClass: "\(OneView.self)"])
}
}
}

struct OneView_Previews: PreviewProvider {
static var previews: some View {
OneView()
}
}

关于firebase - 将 Firebase 分析与 SwiftUI 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65795878/

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