How to log Firebase Analytics screen name in a SwiftUI app?

∥☆過路亽.° 提交于 2021-01-20 16:54:24

问题


I'm trying to log screen names in my app but I have like 95% not set in Firebase Analytics.

In onAppear for a view I do Analytics.setScreenName("screenName", screenClass: "screenName")

Should I do this differently? It seems that Analytics for iOS works in conjunction with UIViewControllers but since this a SwiftUI app and there is no documentation on how to work with that.


回答1:


We are working on a better solution for this. As you mentioned, the way the view controller hierarchy of a SwiftUI app is made up, this is not entirely trivial to solve, but we've got a couple of ideas.

In the meantime, you might want to try this workaround that some people have suggested on the Github issue:

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  Analytics.setScreenName("todo_tab", screenClass: String(describing: type(of: self)))
}


来源:https://stackoverflow.com/questions/59515618/how-to-log-firebase-analytics-screen-name-in-a-swiftui-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!