Reputation: 138
I have an IOS app with Firebase enabled.
Now im currently trying to add a macOS swift app to this project but i cant figure it out how to do it.
( I know that there is an option to port IOS apps to macOS, but i want two separate apps with different functions, one for IOS and one for macOS )
There is no option (as far as i know) in Firebase Admin to add a macOS app so i created a new IOS app in Firebase Admin and tried to set up with the macOS app project. (most likely this is the problem with my whole question)
I get these errors in my AppDelegate when i run my macOS project:
The default Firebase app has not yet been configured. Add
[FIRApp configure];
(FirebaseApp.configure()
in Swift) to your application initialization.An uncaught exception was raised
Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore
Terminating app due to uncaught exception 'FIRIllegalStateException', reason: 'Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore'
Althougth i've used FirebaseApp.configure()
in my applicationDidFinishLaunching
.
Also i imported every single pod but nothing helped me.
pod 'Firebase'
pod 'Firebase/Core'
pod 'Firebase/Analytics'
pod 'Firebase/Auth'
pod 'FirebaseDatabase'
pod 'Firebase/ABTesting'
pod 'Firebase/Database'
pod 'Firebase/Firestore'
pod 'FirebaseFirestore'
pod 'Firebase/Functions'
pod 'Firebase/Messaging'
pod 'Firebase/RemoteConfig'
pod 'Firebase/Storage'
My question is that what could i possibly did wrong?
Or Firebase does not support macOS apps?
If yes then how can i use my existing Firebase IOS project with a new macOS Swift app?
Upvotes: 6
Views: 5035
Reputation: 35648
The answer from Sipos Péter is good and here's a few additional tips.
The podfile in the other answer is spot on. But, the loading sequence for macOS apps is different so you'll need your firebase code earlier in the sequence for stability.
So, no firebase code is needed in AppDelegate. Move that code to the main viewControllers viewDidLoad function and create a class var to reference Firebase. Like this:
var ref: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
FirebaseApp.configure() //set up Firebase
//a class reference to your firebase, This is optional but saves typing
self.ref = Database.database().reference()
let version = Database.sdkVersion() //print out the sdk if needed
print("Firebase Version \(version)") //just prints the current Firebase version
self.authToFirebase() //your function to handle auth'ing this user
//continue app setup
self.myTableView.dataSource = self
self.myTableView.delegate = self
}
Upvotes: 1
Reputation: 138
Someone had the same issue in GitHub. Also i got told that a lot of my pods are actually ios pods so i changed my Podfile to this:
pod 'FirebaseCore'
pod 'FirebaseAuth'
pod 'FirebaseDatabase'
pod 'FirebaseStorage'
Also i changed my AppDelegate file to this:
override init() {
FirebaseApp.configure()
Database.database().isPersistenceEnabled = true
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
Database.database().reference()
}
This seems to fix my problem (at the moment, i hope it is the final fix)
Upvotes: 0