Using Firebase with backgroundTask SwiftUI

144 views
Skip to first unread message

Abdulrahman Ghalayini

unread,
Jul 23, 2023, 11:35:59 AM7/23/23
to Firebase Google Group
Hi Everyone,

Any of you succeeded in using Firebase with backgroundTask of SwiftUI?

Whenever trying to insert a new SwiftUI scene modifier backgroundTask, a fatal error is fired:

FirebaseStorage Storage.swift Fatal error Unexpectedly found nil while unwrapping an Optional value

Looking forward to learn from your experience in this task

Shwe Phe

unread,
Jul 23, 2023, 8:44:04 PM7/23/23
to fireba...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/50444d5f-8cd0-4b9a-98c6-ff0c6089f2abn%40googlegroups.com.

Abdulrahman Ghalayini

unread,
Jul 25, 2023, 7:20:53 PM7/25/23
to Firebase Google Group
never mind guys, i was able to resolve the issue as follow.

I used to use AppDelegate inside my app to launch FirebaseApp.configure() but when using the SwiftUI Scene modifier .backgroundTask, it seems there is a run on the view model (where I initialize Firestore and FirebaseStorage).

I noticed that AppDelegate takes longer time than the launching of the app or basically the scene, therefore the app started trying to access view model before AppDelegate completed its work. Accordingly the FirebaseApp.configure() not yet initialized.

So I moved the FirebaseApp.configure() from AppDelegate to the view model init() before the initialization of Firestore and FirebaseStorage inside the init(). and it Worked!!!!!

I don't know if this way is appropriate or is there a better way to implement.

If any of you guys can comment on which way is better (keeping the FirebaseApp.configure() in the AppDelegate or just move it to the view model)?
Reply all
Reply to author
Forward
0 new messages