Firebase Realtime on iOS: Cannot access Realtime Database - ios

I am getting the following error:
[Firebase/Database][I-RDB034005] 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
Permissions on admin console are set .read and .write to false
I understand the error. when I run the following command and print the value of variable:
Database.database().reference()
I get (cant edit it):
https://bananas-31fe5-default-rtdb.firebaseio.com
And on admin console I have (cant edit it):
https://bananas-31fe5-default-rtdb.europe-west1.firebasedatabase.app
On admin console, I tried creating a new database (and disabling the primary one) on the US, but the one on xcode doesnt seem to change.
My gut feeling is this has to do with the pod library not being updated to enable multiple db location (EU is in beta).

firebaser here
For non-US-central databases the SDK may not be able to read the information from the plist file, so you have to pass it in the code.
You can pass the database URL into the call to database, like:
Database.database("https://bananas-31fe5-default-rtdb.europe-west1.firebasedatabase.app").reference()
See docs for that method override.

When you create a realtime database for the first time, DATABASE_URL is added to your GoogleService-Info.plist file on the server side. You may be getting an error because the GoogleService-Info.plist is outdated and does not contain DATABASE_URL. You can download your updated GoogleService-Info.plist file from your Project Settings and try again.
I hope it helped

Related

Swift 4 Get Keychain Data from Another Project

So I developed an iOS app called Due it a while back, and I had no idea what I was doing at the time. Anyhow, I lost all of the files for it, so i decided to re-create the project, but I stored data in Keychain on the old version. Is there any way that I can get the Keychain data back? (im using the same Bundle Identifier)
I've tried using this: https://stackoverflow.com/a/44310869/4705065 but it doesnt find any data.
Not at this point.
You are able to add multiple applications to a Keychain Access Group within an app, but you would have had to do that within the original app you no longer have access to.
More information on Keychain Access Groups.
It would be a big security concern if anyone could access anything within keychain without explicit permission.

Realm Sync data resets on app reinstall

I have an iOS app which uses Realm locally and it works great, and my intention is to use Realm Object Server to enable:
Data sync across devices
Data restoration on app reinstall
I've been having a lot of trouble with the last one. The flow in my app is the following:
First, it tries to find a User in my Realm Sync. If a User exists, go to step 4. Otherwise, go to step 2;
Ask for the user's name, income and payday;
Get the user's userRecordID for iCloud and logIn to Realm Object Server.
Use the SyncUser's identity as the User entity identifier. Save the data I just asked (name, income and payday) to Realm;
Go to main app screen and let the user enjoy the app.
ROS is using cloudkit based authentication. The problem occurs if I follow steps 1-4 above, and then reinstall the app. I expected the previously created User to be retrieved in step 1, but instead all of its fields beside the primary key are set to blank values (name becomes empty string, income and payday become 0). Is this behavior expected? Is what I want to do within the purpose of Realm?
EDIT
Made the flow clearer after #AustinZ's answer.
"Data restoration on app install" is definitely a valid use case for Realm Sync. However, the flow you describe is problematic.
A synchronized Realm is identified by two pieces of information: a sync user and the Realm's path on the Realm Object Server (e.g. /~/my/realm). If you have the same sync user logged into multiple devices, and they each open a copy of a Realm at the same path, they are opening the same synced Realm and will stay in sync with each other.
However, to get the same sync user, a user needs to log in to the Realm Object Server from their device. You do this by creating a CloudKit SyncCredentials value using SyncCredentials.cloudKit(token:) and passing that credential to SyncUser.logIn(). The device will then communicate with the Realm Object Server, and if the log in succeeds, then the logIn() method's callback block will be invoked and will give you a SyncUser. That is the sync user you need to use to open Realms.
So:
You shouldn't be saving users or user info to Realms manually. We persist the relevant information automatically.
If a user deletes and re-installs their app, the app's documents and files are deleted as well, which means you shouldn't assume you can access a Realm's data after the app which created it was re-installed.
What you should be doing is, in step 3, using the user's CloudKit credentials and logging into the Realm Object Server as described above.
Please review our documentation for more information.

Is replacing the GoogleService-Info.plist enough to make someone else's app work with my bundle identifier?

I recently got an app from an iOS developer, and it is working with his bundle identifier in xCode. but when I change the bundle identifier to mine, it stops working(database is not connecting). What should I do to make it work? Making a new Firebase account and use my bundle identifier to get a new GoogleService-Info.plist and replace it with his GoogleService-Info.plist is enough ? (I did that too but still not connecting to the database) what have I missed ?
UPDATE
I want to connect to my new empty database that comes with the new firebase account , not the previous database.
If you read the GoogleService-Info.plist the DATABASE_URL should be different in two files. Thats why you can't connect to the previous database. You can export data from the first one and then import those json to the new database. Is this solution okay for your case?
Updated
Okay, step by step. There are error messages showing in the XCode console. Do you know how to find them? I created a Firebase file, replaced a new plist. And then I run the app, when I try to sign up. It shows a pop up "Problem with creating a new user, Problem connecting to database, Pleaes try again later". But the important thing is! This is not the error code. When you look at the XCode console, it shows:
<FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=501 "(null)" UserInfo={msg=Missing device credentials. Retry later.}
<FIRInstanceID/WARNING> Failed to retrieve the default GCM token after 5 retries
Then you can google it.
How to fix Failed to fetch default token error?
after trying so much time I found the error it was
FIRAuthErrorCodeOperationNotAllowed = 17006
Indicates that email and password accounts are not enabled. Enable them in the Auth section of the Firebase console
to get rid of this all I have to do was go to,
https://console.firebase.google.com/project/myproject/authentication/providers
and select Sign-In method and enable email and password

My iOS app does not appear on Firebase dashboard

My app is live on the App Store and there are no crashes on the front end however when I log in to Firebase I cannot find it on the dashboard. I tried copy & pasting the database URL but I got the message saying that there was an error making the request and that I should try again later. Has anyone else encountered this issue and could advise me on who to contact to resolve it?
According to the Firebase Status Dashboard, there should be no issues with the Realtime Database at the moment.
Assuming that your app was associated with your Firebase account previously and just suddenly disappeared, I have not heard of/ encountered anything similar in the past.
One thing to try is to make sure you are logged into the correct account and have selected the correct project.
Since accessing the database directly through its URL says to try again later, this might be a temporary problem that is resolved shortly.
However to make sure, your best option at this point is probably to reach out to Firebase support directly using this form (requires sign-in).

How do i customize my root reference?

I am fairly new to Firebase and i have just finished adding Firebase authentication to my app. Now, i want to move to the next step which is to save a users account information on the database. I am confused where it come to creating my root reference. Say for example, i want my app's root Reference to be:
Firebase rootRef = new Firebase("<My-URL>/android/apps/")
How do i add the sub-directories /android/apps/ to my database so that it shows on the firebase console?
The database page on the firebase console is still very confusing to me, please below is a screen shot of my console. I have marked two places in red. Please can somebody tell me the uses of these places.
Screen shot of firebase console

Resources