import SwiftUI
import Firebase
@main
struct AnalyticsCrashlyticsDemoApp: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
VStack(spacing: 20) {
Button("Log Event Button") {
Analytics.logEvent("button_tapped", parameters: ["button_name": "log_event"])
}
.accessibilityLabel("Log Event Button")
.buttonStyle(.borderedProminent)
Button("Cause Crash Button") {
fatalError("Test Crash triggered")
}
.accessibilityLabel("Cause Crash Button")
.buttonStyle(.bordered)
}
.padding()
}
}We start by configuring Firebase in the app's initializer to enable Analytics and Crashlytics.
The UI uses SwiftUI with two buttons stacked vertically.
The first button logs a custom event named button_tapped with a parameter button_name set to log_event. This helps track user interaction in Analytics.
The second button triggers a crash using fatalError to test Crashlytics crash reporting.
Both buttons have accessibility labels for screen readers and use SwiftUI's button styles for clear visual distinction.