Firebase is uploading & fetching data on another app server - flutter

I was working on 2 projects at a time. Everything was working fine but when I uploaded my data from my app to the firestore, it was not found in the firestore. After checking it I found that it is uploading my data to my another firebase app database. Please help me resolving the issue I cannot find the error. It was working fine before, now both the apps are crashing.

My best guess is that you switched up the files that contain the information on how to connect to Firebase between these projects.
If you recently created these apps, that data is likely in a firebase_options.dart file that was created by the flutterfire CLI command.
But otherwise the information may also be stored in a google-services.json file for Android, and a GoogleService-Info.plist file for iOS.
Whichever of these it is, you'll want to check the data in these files and update them to refer to the correct Firebase project for each app.

Related

Flutter app losing local data when user closes the app

My app uses both shared_preferences and writing to a local json file (getting path using path_provider) for the data that it uses. I recently started testing it (starting 1/1/22) with a larger group and some people are having an issue where the data is lost when they close the app and reopen it. We're testing on both Android and iOS. The first user to have the issue was on iOS and has had it from the beginning. All the other users ran into the problem a couple of days ago (1/12/22) and is a mix of mostly iOS and 1 Android user.
The data persists while the app is running since it's consistent while the user navigates around. I haven't been able to replicate the problem myself and I haven't been able to find out what the issue in my research. Any thoughts of what may be going on?
I found a similar question that mentioned that path_provider provided different paths for storage, but that doesn't seem to be my issue here since the first piece of data that gets called is the shared_preferences data and that is also getting lost.
I did some troubleshooting and we figured out that the devices (mostly iOS) were deleting the data point from shared_preferences. I migrated that point of data to a json file and the issue disappeared. It does say in the documentation not to use shared_preferences for any critical piece of data and now I see why. It worked initially, but had issues later for a lot of people, so I'm probably not going to use it in the future.

Firebase Connection Killed

I have integrated Firebase into my iOS project. I have been using Firebase for years across many projects. This specifically is using the Firestore. I can authenticate fine and write to the database. However, after the write is complete, even though it's successful, I receive the following message:
Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Firebase error. Please ensure that you spelled the name of your Firebase correctly
The bundleID was copied and pasted directly from the app to the Firebase setup. I even deleted the app from Firebase and created it again. I have downloaded the GoogleService-Info.plist and I checked that the bundle there matches the bundle of the app. I can see nothing wrong here and again functionality is working fine.
The only instance I saw of this message browsing around was with a non-US based developer and it was suggested that additional config was required. However, that is not the situation for me. What else might cause this error to be generated?
The error message seems to point towards Realtime Database, despite your interest in Cloud Firestore.
I recommend:
Making sure you're using the latest SDK. Old SDK versions (before mid 2020) might require the Realtime Database URL to be present in the plist file, which isn't always the case anymore.
If step 1 doesn't solve the problem, you can:
Force the creation of a Realtime Database instance in the Firebase console.
Download the updated plist file and add it to your project.
If you end up with the second solution, can you comment with the SDK version you're using, so that I can check for issues in that?

PhoneGap based App does not work after After App update in iOS5.1

I have a PhoneGap based iOS app which uses SQLite DB for offline storage. The app is not working after an app update in iOS 5.1. The same app is working fine in versions below 5.1.
I explored few things and my analysis is
When we install a app iOS creates a separate sandbox for that and all the data related to that app goes in to that.
in iOS5.1 when we update an app new sandbox is created and the contents from old sandbox is moved here.
For WebSQL i.e SQLite for PhoneGap in iOS 5.1 the DB is stored under caches folder(volatile storage). But in previous version of iOS the SQLite DB was stored under Documents folder in Sandbox which is persistent storage.
The real problem is there is a file called ".preferences" in caches/preferences that has the path of websql DB. when i do an app update the sandbox path changes but in this file the previous sandbox is path is still available due to this the app is not working as the previous path is already deleted from device.
Is this an Apple issue or can it be resolved by a developer?
I have fixed the issue by
The path referred by iOS to find WEB DB(SQLite) and Local storage is stored in NSUserDefaults.
So when i launch the app every time i check the path information and make sure it matches new sandbox path if not i set the value for that Key and now the app works fine.
NSUserDefault Key referred to SQLite path is WebDatabaseDirectory.
If Apple releases a fix for this issue in their next release, this code is not required.
Try to use cordova-1.6.0 or above this.
When I changed to cordova-1.6.0 , my problem is fixed.

Phonegap (1.4.1) Storage not working anymore with iOS 5.1

I developed an App for Android and iOS using Phonegap. Both Apps are already running successfully and available on the stores. Now I added some changes for an Update. If I have data stored (using the SQLite database) in the previous version and updating to the new one, the Storage Api on IOs 5.1 is not working anymore.
If I call
var db = window.openDatabase("mydb", "1.0", "", 5000000);
nothing happens.
It's working fine for Android, it's also working if I do a new install or if I do not have data already stored in the database from the previous version of my app. I'm using other Phonegap functions like Notification or localStorage, which are working perfectly fine.
Any help would be much appreciated, since I'm really running out of ideas :)
There is a fix for both issues with Webkit storage and iOS 5.1
Storage moved from /Webkit to /Cache
Storage is not adjusted to updated folder structure on an App update under iOS 5.1 (WebKit Bug)
https://issues.apache.org/jira/browse/CB-330
This solution seems to be more safe than just changing the location of Webkit data calling a private API. While the App is running the Webkit storage locations are used. On resuming or terminating all data is backuped to the documents folder. Timestamps ensure that ab old backup cannot overwrite newer storage data (if the app crashes...).
The best: Users that are on an older iOS Version using an App with that fix in it, will not suffer damage lost in case of any iOS updates. Thats why one should not wait...
It's strange, it should be working... By the way, in iOS5.1, WebSQL is considered tempory data that can be deleted at any time...
It's possible to change the location of WebKit data calling a private API. You should be able to set the location to a secure folder like Documents. I did not test this solution yet, but look at this post :http://stackoverflow.com/questions/4527905/how-do-i-enable-local-storage-in-my-webkit-based-application
I think the safer way is to use SQLite (same as WebSQL) with a phonegap plugin. That plugin save the database in the Document folder, that mean that the DB is not deleted and is saved by iCloud.
Here is the Native SQLite phonegap plugin : https://github.com/davibe/Phonegap-SQLitePlugin
Regarding this plugin, there are some differences between the WebSQL API, here is an adaptor:
https://gist.github.com/2009518
You should also migrate the old WebSQL db file (stored in Library/WebKit or Caches directory) to the Document folder. Here is a code to do that :
https://gist.github.com/2009491
There is also a fix implemented in the latest version of Cordova : https://issues.apache.org/jira/browse/CB-330 (it makes a backup of the DB files in the Document folder)
And if the data are important, you should save it to a server. I wrote a small lib to synchronize the SQlite DB to a server :
https://github.com/orbitaloop/WebSqlSync
There has been a Jira issue created on this: localStorage / SQLDatabase Error after App update

Connecting CoreData to my App on an iPhone Device

I apologize ahead of time for what I'm sure is a complete newbie lapse. Running my iPhone app on iPhone simulator - no problem. But I loaded the app on an iPhone device for the first time and it appears as if the SQLite database I'm using (NSManagedObjectContext) isn't connected or didn't upload. The app installs but with no data. How do I get it all to upload and work on the device?
I appreciate any help.
lq
The first rule with Core Data is that you should never ever touch the store directly. It should be considered a black box and only accessed via the the Core Data APIs. Accessing the database directly is unsupported and can lead to data corruption.
What you should do instead is create a trivial desktop application (or command line is you are just importing from another source) and enter the data there. Once the data is entered then copy the sqlite file to your mobile application and include it in the bundle. That way you are accessing the file from Core Data. Since Apple can and does change the structure of that file without notice your application will be future proof.
update
If you have created a database using Core Data you can then take that sqlite file and add it to your Xcode project for your iPhone application. Xcode will then copy it into the app bundle when it compiles the project.
Looking a little deeper I found a link that answers my own question. So anyone with the same question, this solved the issue for me:
http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/