How to remove firebase database - ios

Please tell me, how can I delete the entire database from firebase immediately, documentation or other information could not be found, can anyone come across this before?
it,s easy
db = Database.database().reference()
let usersReference = db
usersReference!.removeValue()

db = Database.database().reference()
let usersReference = db
usersReference!.removeValue()

Create an empty JSON file and import it to firebase database.

Related

Flutter Firebase Database persistence not working

I am using the firebase_database plugin in version 1.0.1 with flutter currently testing on android.
I access the database with a singleton.
GlobalFBInstance._internal() {
final firebaseInstance = FirebaseDatabase.instance;
firebaseInstance.goOnline();
firebaseInstance.setPersistenceEnabled(true);
firebaseInstance.setPersistenceCacheSizeBytes(10000000);
databaseRef = firebaseInstance.reference();
databaseRef.keepSynced(true);
storageRef = FirebaseStorage.instance.ref();
}
Everytime after an app restart the app needs internet to get the database. I thought with the persistence and keepsynced there is no need for internet? If I have a very bad connection(tested in the emulator and on a device) it takes forever to load a gridview containing four simple strings from the database.
When I load a datasnapshot with:
Future<DataSnapshot> getDatabaseSnap(String location) async {
var _newref = databaseRef.child(location);
await _newref.keepSynced(true);
return await _newref.once();
}
it won't load if there the internet connection is slow.
What could be the reason for this? Is there a better way to make sure the database doesn't need a connection every time?
Thanks in advance.
Edit: When waiting for persistence I get false:
bool ispersistant = await firebaseInstance.setPersistenceEnabled(true);
Don't use FirebaseInstance to toggle persistent storage. Use FirebaseDatabase object to hold the instance and then set it to enable.
FirebaseDatabase database;
database = FirebaseDatabase.instance;
database.setPersistenceEnabled(true);
database.setPersistenceCacheSizeBytes(10000000); // 10MB cache is enough
Class Persistence Firebase database
class RealtimeDataBase{
late FirebaseDatabase firebaseDataBase;
late DatabaseReference databaseRef;
RealtimeDataBase(){
firebaseDataBase = FirebaseDatabase.instance;
firebaseDataBase.setPersistenceEnabled(true);
firebaseDataBase.setPersistenceCacheSizeBytes('specify any value');
databaseRef = firebaseDataBase.ref();
}
}

Firebase Database taking 10 to 12 seconds to get the data, iOS Swift 4

I'm using Firebase database for my chat and using a query to get the data from. Query is as follow,
DispatchQueue.main.async {
self.channelRefHandle = self.channelRef.queryOrdered(byChild: "userid1")
.queryEqual(toValue: String(describing: getMyUserDefaults(key: MyUserDefaults.UserId)))
.observe(.value, with: { (snapshot:FIRDataSnapshot) in
})
}
I've a database structure like below image
I'm not getting the exact issue that the above query getting too much time to load the record.
I've 9000 around record on Firebase Database.
If anyone have any idea please suggest me.
Thank you.

iOS Firebase : Add data to firebase node of array type

I got node in the firebase named "XXXXX".
I want to add tokenids to this node.
But in iOS I am having problem updating tokensids.
Do we got functions in iOS for appending data to iOS Firebase?
or we have to first get the token from firebase , append our token and save the token array back to node ?
Any suggestion guys ?
No, you cannot append data to an array in Firebase using any Firebase query.
But, there is a way by using dictionary as arrayObjectToAdd: true,
self.ref.child("ArrayMainNode").setValue(["arrayObjectToAdd": "true"])
To remove an array object, you can directly use
self.ref.child("ArrayMainNode").child("arrayObjectToAdd").removeValue()
You can do it this way:
let ref = FIRDatabase.database().reference(withPath: "somePath/array").child(newArrayObjectKey)
ref.setValue("true") // or whatever
Hope it helps
You can do it by this way:
let refInsert = Database.database().reference()
self.refInsert.updateChildValues(["Your node": "\(new token)"])

Firebase does not update values throughout an app until the user is logged out

So, I have been coming across a problem where my Firebase app does not update user values when a user makes an update. To be more clear: Lets say user 1 has a photo of a dog and then changes it to a cat.
Once they change it to a cat, my node value in Firebase is successfully updated but the user themselves won't be able to see the change in other previously loaded areas in the app (other places with the dog picture) until they log out and then log back in.
For this reason I was wondering if there was any way to conduct a background app refresh that way all previous dog values in the app are changed to cat values without the user having to log out and then log back in. Please note that this same problem occurs not only with my user's profile picture but also any other user field I have setup.
Here is how I am updating a node value for my user in Firebase:
let storageRef = FIRStorage.storage().reference()
_ = FIRStorageMetadata()
let filePath = "\(FIRAuth.auth()?.currentUser?.uid)/\("userPhoto")"
let profileImageData = UIImageJPEGRepresentation(self.profilePicture.image!, 1.0)
if let data = profileImageData {
storageRef.child(filePath).put(data, metadata: nil){(metaData,error) in
if let error = error {
print(error.localizedDescription)
return
} else {
let downloadURL = metaData!.downloadURL()!.absoluteString
let userPhotoUpdateRef = FIRDatabase.database().reference().child("users").child(self.currentUser).child("userPhoto")
userPhotoUpdateRef.setValue(downloadURL)
}
}
}
If you have any questions please ask! Any help would be appreciated!
The Firebase SDK for Cloud Storage provides an easy way to read file from and write files to cloud storage. It does not provide a way to monitor those files.
The easiest way to provide a monitoring approach is to write the metadata of the files to the Firebase Realtime Database. See this short section in the Storage docs for a brief mention of that: https://firebase.google.com/docs/storage/ios/file-metadata#custom_metadata
When you write data to a location in the Firebase Database, all apps that are actively monitoring that location will be instantly updated. When they get that update, you can reload the image from Cloud Storage for Firebase.

New Firebase - Cannot query data. What is the new syntax?

I am trying to move to the new Firebase from the old one (launched today, May 18th, 2016), but the query syntax is unclear to me. The only example I can find to make a query is via a listener.
I've followed the docs (https://firebase.google.com/docs/database/ios/retrieve-data), but they are very unclear as to how to simply query one piece of data in the Firebase realtime DB.
The old docs were fine, but the new ones are terrible, imo. Also, their examples on github, where I got some of the code I'm now trying to use, are overly complex (https://github.com/firebase/quickstart-ios/tree/master/database/DatabaseExampleSwift).
The code runs fine, I have a new project set up in the Firebase admin console online, I have the new plist file set up and in xcode, and everything compiles fine. I just need code to easily access one measly piece of data! Plz help.
Thanks.
Here's my code (runs fine / is configured fine), but can't display the data:
class LatestNewsTableViewController: UITableViewController {
// get the Feed URL from Firebase:
lazy var FireBaseRef: FIRDatabaseReference = FIRDatabase.database().reference()
var FeedURLRef: FIRDatabaseReference!
var refHandle: FIRDatabaseHandle?
Then, in viewDidLoad(), I'm doing this:
FeedURLRef = FireBaseRef.child("AppGlobals").child("FeedURL")
refHandle = FireBaseRef.observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) in
let FirebaseFeedURL = snapshot.value as! [String : AnyObject]
print("FirebaseFeedURL = " + String(FirebaseFeedURL))
})

Resources