简体   繁体   中英

Firebase SDK for Swift, Not automatically sending events

I've created an Swift App using SwiftUI lifecycle.

I followed the instruction here

I installed Firebase SDK using Xcode not CocoaPods.

What I wanted is that Firebase send an event whenever a user open a "View".

Here is my code snippet.

import SwiftUI
import UIKit
import Firebase

@main
struct my_App: App {
            
    init() {
        FirebaseApp.configure()
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

and another file for a view.

import SwiftUI
import FirebaseAnalytics


struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("Hello World")
        }
    }
}

However, When I add Analytics.logEvent("CustomView", parameters: nil) to ContentView.

Firebase sends the event data.

Is there an argument to set to automatically send event whenever a View is appeared?

Thanks

Add the FirebaseAnalyticsSwift target to the project. (See https://www.kiloloco.com/articles/010-add-package-product-xcode/ ) and add import FirebaseAnalyticsSwift to the source.

See the implementation at https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseAnalyticsSwift/Sources/Analytics%2BSwiftUI.swift .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM