前提
FirebaseFirestoreから取得したデータに応じてアプリを起動した際に表示する画面を決定するのですが、このようなエラーが表示されてクラッシュしてしまいます。Firebaseをすぐに使いたい場合はどうすればよいでしょうか。
実現したいこと
エラーの解決
発生している問題・エラーメッセージ
Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore
該当のソースコード
Swift
1import SwiftUI 2import FirebaseCore 3 4class AppDelegate: NSObject, UIApplicationDelegate { 5 func application(_ application: UIApplication, 6 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { 7 FirebaseApp.configure() 8 9 return true 10 } 11} 12 13@main 14struct TermApp: App { 15 @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate 16 @ObservedObject var model: WebViewModel = WebViewModel() //Firebaseからデータを取得する 17 18 var body: some Scene { 19 WindowGroup { 20 if TermWebView().currentUrl != TermWebView().termUrl{ 21 NewTermView() 22 }else if PolicyWebView().currentUrl != PolicyWebView().policyUrl{ 23 NewPolicyView() 24 }else{ 25 ContentView() 26 } 27 } 28 } 29}
struct TermApp に @main があると AppDelegate は呼ばれないかも。
https://stackoverflow.com/questions/68884303/swiftui-appdelegate-not-being-ran-whenever-app-is-opened

回答1件
あなたの回答
tips
プレビュー