When the user registers for my app they choose a profile picture, input a name, email, and password. I use firebase to authenticate them using email and password. I am using FIRAuth.auth()?.addAuthStateDidChangeListener
to detect the change in a user's authentication status. If the user has been authenticated the code inside executes (this code sends the user to the next viewController). The problem is that the code inside fires off before my data can be added to the realtime database and FirebaseStorage. Is there a way to monitor when both tasks have succeeded so then I can trigger the change of view controllers? Thank you.
The Firebase SDKs for Cloud Storage add Google security to file uploads and downloads for your Firebase apps, regardless of network quality. You can use our SDKs to store images, audio, video, or other user-generated content. On the server, you can use Google Cloud Storage APIs to access the same files.
Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing: Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model.
Firebase has a tutorial on how to track the progress of file uploaded to their servers:
let storageRef = FIRStorage.reference().child("folderName/file.jpg");
let localFile: NSURL = // get a file;
// Upload the file to the path "folderName/file.jpg"
let uploadTask = storageRef.putFile(localFile, metadata: nil)
let observer = uploadTask.observeStatus(.Progress) { snapshot in
print(snapshot.progress) // NSProgress object
}
This snapshot gives you useful information, such as the total size of the file in bytes and how many bytes have been uploaded so far. Using this information, you can calculate the percentage uploaded and use it to update any UI control in your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With