Firebase configuration not working - ios

the Firebase configuration is not working even though it is called in the app delegate method
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure();
confic(application: application);
return true
}
I did not had this problem before where my classes were initialised as singletons those particular classes are dependent on Firebase however I decided to instantiate them individually in each view controller instead of using singletons however now I'm getting this issue can anyone help?.
I also tried removing any calls to Firebase from the Appdelegate class and just have FirebaseApp.configure(); included in the delegate however this did not help either.
theconfic(application: application); method contains all my Firebase related calls such as checking if the user has logged in etc.
I moved in here as in previous post I read this may help however it made no difference still getting the same error
Error message
2018-05-16 16:23:42.201080+0100 Jagdschule Gut Grambow[1983:376501] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The default FIRApp instance must be configured before the default FIRAuthinstance can be initialized. One way to ensure that is to call [FIRApp configure]; (FirebaseApp.configure() in Swift) in the App Delegate's application:didFinishLaunchingWithOptions: (application(_:didFinishLaunchingWithOptions:) in Swift).'
* First throw call stack:
(0x1841cad8c 0x1833845ec 0x1841cac6c 0x1021d8244 0x10213b510 0x1021321e8 0x1021209cc 0x102120b5c 0x18e40dedc 0x18e56f628 0x18e56f7a0 0x18e56f360 0x18e23d2c8 0x18e26b4d0 0x102097890 0x102097940 0x18e40dedc 0x18e56f628 0x18e56f360 0x18e23cf24 0x10216b674 0x10216b728 0x18e40dedc 0x18e56f628 0x18e56f360 0x18e40db84 0x18e40e31c 0x18e56f628 0x18e56f7a0 0x18e56f360 0x18e40ced4 0x18e719d88 0x18e17bfd8 0x18dd99254 0x18dd67550 0x18e397a0c 0x18dd66e4c 0x18dd66ce8 0x18dd65b78 0x18e9fb72c 0x18dd65268 0x18e7e09b8 0x18e92eae8 0x18dd64c88 0x18dd64624 0x18dd6165c 0x18dd613ac 0x1869c8470 0x1869d0d6c 0x103aa9220 0x103ab5850 0x1869fc878 0x1869fc51c 0x1869fcab8 0x184173404 0x184172c2c 0x18417079c 0x184090da8 0x186073020 0x18e07178c 0x102130644 0x183b21fc0)
2018-05-16 16:23:42.201344+0100 Jagdschule Gut Grambow[1983:376766] 5.0.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add [FIRApp configure]; (FirebaseApp.configure() in Swift) to your application initialization. Read more:
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Related

Failed to get default firebase instance in swift

As I was working on my iOS app, I got this error out of no where
Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'Failed to get default Firebase Database instance. Must call `[FIRApp configure]` (`FirebaseApp.configure()` in Swift) before using Firebase Database.'
on the line initializing DB_BASE
var DB_BASE = Database.database().reference()
class DataService {
static let instance = DataService()
}
I have FirebaseApp.configure() in my didFinishLaunchingWithOptions AppDelegate function, so I'm not sure what the error is all about. I've tried updating pods, restarting my computer, but no luck so far.
I haven't worked with Database specifically, but we use Storage, Analytics and Remote Config. Have you put google-services.json to the root of the project?
The code you provided doesn't make it totally clear, but if DB_BASE by any chance is a member of a singleton (like DataService.instance), try moving it to a different place. Static variables get inited before applicationDidFinishLaunching is called.

FirebaseApp.configure() crashing on second time launch after clean installation

I am using Firebase inside my app and calling FirebaseApp.configure() inside didFinishLaunchingWithOptions . Now my app works fine when I do a clean installation (delete the app and install again) and run it for the first time. But when I re-run the app the second time, it crashes on FirebaseApp.configure() with
2019-11-11 12:02:43.166729+0530 MyAppName[885:135491] 6.11.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2019-11-11 12:02:43.176694+0530 MyAppName[885:135418] -[FIRInstanceIDTokenInfo isFresh]: unrecognized selector sent to instance 0x281bc8a80
2019-11-11 12:02:43.179909+0530 MyAppName[885:135418] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FIRInstanceIDTokenInfo isFresh]: unrecognized selector sent to instance 0x281bc8a80'
*** First throw call stack:
(0x1a267180c 0x1a2399fa4 0x1a257536c 0x1a2675c88 0x1a2677a6c 0x102e632fc 0x102e48844 0x102e48714 0x102e48530 0x102986b70 0x102986e0c 0x1029869e4 0x1029811dc 0x102980c18 0x102980b64 0x10264ea14 0x10264e7d4 0x10264eb7c 0x1a66d0ef4 0x1a66d2d20 0x1a66d8554 0x1a5ea6cdc 0x1a633bfc4 0x1a5ea77c4 0x1a5ea721c 0x1a5ea75f0 0x1a5ea6eac 0x1a5eab3c8 0x1a626e6a4 0x1a63555b0 0x1a5eab100 0x1a63554ac 0x1a5eaaf6c 0x1a5d1cba4 0x1a5d1b70c 0x1a5d1c8dc 0x1a66d68d4 0x1a628f09c 0x1a7776850 0x1a779b8e8 0x1a7780fb4 0x1a779b5a4 0x107b1abd8 0x107b1dffc 0x1a77c04c8 0x1a77c0194 0x1a77c06bc 0x1a25ef7c4 0x1a25ef71c 0x1a25eeeb4 0x1a25ea000 0x1a25e98a0 0x1ac541328 0x1a66da768 0x102654b44 0x1a2474360)
libc++abi.dylib: terminating with uncaught exception of type NSException
To setup firebase I am using the following
private func setupFirebase() {
FirebaseApp.configure()
Messaging.messaging().delegate = self
}
I am using Cocoapods for installation and Firebase version that I'm using is 6.11.0
Please pod update to Firebase 6.12.0.
We suspect that this is related to https://github.com/firebase/firebase-ios-sdk/issues/4167 that was fixed in 6.12.0.

iOS AppDelegate crashes when adding didReceiveRemoteNotification

I have the following App delegate for an iOS app in Xcode 8.3:
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
}
}
When I start my app in either the simulator or on a device, it crashes with the following message:
2017-07-04 21:26:04.284336+0200 MyApp[352:25788] -[NSTaggedPointerString containsObject:]: unrecognized selector sent to instance 0xa00000070696f764
2017-07-04 21:26:04.284569+0200 MyApp[352:25788] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [NSTaggedPointerString containsObject:]: unrecognized selector sent to instance 0xa00000070696f764'
*** First throw call stack:
(0x188baefe0 0x187610538 0x188bb5ef4 0x188bb2f54 0x188aaed4c 0x18ef7d030 0x18ef630f4 0x18ef77d18 0x18ef60474 0x18a757884 0x18a7576f0 0x18a757aa0 0x188b5d42c 0x188b5cd9c 0x188b5a9a8 0x188a8ada4 0x18ed4a384 0x18ed45058 0x100106fc8 0x187a9959c)
libc++abi.dylib: terminating with uncaught exception of type NSException
In the simulator, it's a slightly different error message:
2017-07-04 21:30:10.379 MyApp[55965:1127208] -[__NSCFString containsObject:]: unrecognized selector sent to instance 0x608000028d60
2017-07-04 21:30:10.383 MyApp[55965:1127208] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString containsObject:]: unrecognized selector sent to instance 0x608000028d60'
Removing the application(:didReceiveRemoteNotification) method makes the crash disappear.
Does anyone have any clue what's going on?
Figured out the problem: my Info.plist had 'Background Modes' set to a string instead of an array of modes. Fixing that fixes the crash.
You likely have a third party framework that's causing the issue here. For one, you've posted Swift code, but are getting an Objective-C error message. It's likely that a library you're using is registering itself to handle notifications.
Second, the didReceiveRemoteNotification needs to always call it's completionHandler before exiting. So a blank function will cause issues.
You need to call completionHandler with a parameter of either .newData, .noData, or .failed depending on your results.

persistenceEnabled works in simulator, but raise a NSInternalInconsistencyException on device

I've enable Firebase's disk persistence in my app by setting persistenceEnable to true
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
return true
}
When I run the app in xcode's iPhone simulator everything work as expected but when I run the app on the device I get an NSInternalInconsistencyException.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unrecognized database version: '
*** First throw call stack:
(0x18e68d1b8 0x18d0c455c 0x18e68d100 0x10014323c 0x100143124 0x100154434 0x100de9258 0x100de9218 0x100df6aec 0x100decce0 0x100df7088 0x100df8e2c 0x100df8b78 0x18d71f2a0 0x18d71ed8c)
libc++abi.dylib: terminating with uncaught exception of type NSException
I don't really know what's happening. It looks like the exception is thrown when attaching an 'observe' listener
let ref = FIRDatabase.database().reference()
ref.child("usersEvents").child(userID!).observe(.value, with: { (snapshot) in
...
If I comment the persistenceEnabled = true
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
//FIRDatabase.database().persistenceEnabled = true
return true
}
The app works on my device but of course I loose the offline capabilities.
I've also tried to move the FIRDatabase.database().persistenceEnabled = true but each time I use it the app crashed when executing on the iPhone.
Thanks and regards.
TLDR;
I remove the app from my device and let xCode install a fresh copy of it and that solved the issue.
Full comment :
After some trying to reproduce the issue in an other project for several hours without success I found the solution.
The error message is not 100% clear but gives a good clue Unrecognized database version:
As the app was only crashing on my device when persistenceEnabled was set to true I figured out the issue must have been related to the local database cache.
I remove the app from my device and let xCode install a fresh copy of it and that solved the issue.
Somehow the local Firebase cache must have been corrupted and each time Firebase's sdk tried to access it my app crashed.
I hope this may help someone facing the same issue some days.

How to migrate Realm object that hasn't been stored?

I have an object that I haven't stored anywhere (yet). Even without creating a Realm for it, the app crashes saying this object requires a migration after I've modified it.
I've tried this (in method func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool):
RLMRealm.setSchemaVersion(1, forRealmAtPath: RLMRealm.defaultRealmPath()) { (migration: RLMMigration!, oldSchemaVersion: UInt) -> Void in
if oldSchemaVersion < 1 {
// not needed, nothing stored...
}
}
RLMRealm.defaultRealm()
Log:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Migration is required for object type 'PYDRealmChange' due to the following errors:
- Property 'relativePath' is missing from latest object model.
- Property 'source' has been added to latest object model.
- Property 'target' has been added to latest object model.'
which is what I've found in the documentation. It didn't help and the app is still crashing. My guess is that I need the actual Realm to perform the migration on. So my question is - how do I migrate if there is none?
So problem solved:
What I didn't know is the fact, that I guess that the model object is set in all the realms existing in the app no matter whether I have stored it in them or not. The solution was to copy/paste the code RLMRealm.setSchemaVersion... for all the realm objects in my app. Then it started working.

Resources