Swift
Objective-C
Kotlin+KTX
Java
JavaScript
Dart
Unity
C++
Auth.auth().addStateDidChangeListener { (auth, user) in
if let user = user {
let email = user.email
// ...
}
}
Auth.auth().signIn(withEmail: userEmail, password: password) { (user, error) in
if let user = user {
// ...
}
}
[[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth * _Nonnull auth,
FIRUser * _Nullable user) {
if (user) {
NSString *email = user.email;
// ...
}
}];
[[FIRAuth auth] signInWithEmail:email
password:password
completion:^(FIRUser * _Nullable user,
NSError * _Nullable error) {
if (error) {
// ...
}
}];
val auth = Firebase.auth;
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val user = task.result.user
// ...
}
}
FirebaseAuth auth = FirebaseAuth.getInstance();
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Task task) {
if (task.isSuccessful()) {
FirebaseUser user = task.getResult().getUser();
String email = user.getEmail();
// ...
}
}
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in
var email = user.email;
// ...
} else {
// User is not signed in
// ...
}
});
firebase.auth().signInWithEmailAndPassword(email, password);
FirebaseAuth.instance.authStateChanges().listen((User? user) {
if (user != null) {
// user is signed in
var email = user.email;
} else {
// user is not signed in
// …
}
});
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: emailAddress,
password: password
);
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWithOnMainThread(task => {
if (!(task.IsCanceled || task.IsFaulted)) {
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
}
});
firebase::auth::Auth *auth = firebase::auth::Auth::GetAuth(app);
auth->SignInWithEmailAndPassword(email, password);
// poll the result in your game loop
firebase::Future<firebase::auth::User *> result =
auth->SignInWithEmailAndPasswordLastResult();
if (result.status() == firebase::kFutureStatusComplete) {
if (result.error() == firebase::auth::kAuthErrorNone) {
firebase::auth::User *user = *result.result();
std::cout << Sign in succeeded for email << user->email() << std::endl;
}
}
Swift
Objective-C
Kotlin+KTX
Java
JavaScript
Dart
Unity
C++
let db = Firestore.firestore()
// Write
db.collection("users").document("alovelace").setData([
"firstname": "Ada",
"lastname": "Lovelace"
])
// Read / listen
db.collection("users").document("alovelace")
.addSnapshotListener { documentSnapshot, error in
guard let document = documentSnapshot else {
print("Error fetching document: \(error!)")
return
}
guard let data = document.data() else {
print("Document data was empty.")
return
}
print("Current data: \(data)")
}
FIRFirestore *defaultFirestore = [FIRFirestore firestore];
// Write
[[[self.db collectionWithPath:@"users"] documentWithPath:@"alovelace"] setData:@{
@"firstname": @"Ada",
@"lastname": @"Lovelace"
}];
// Read / listen
[[[self.db collectionWithPath:@"users"] documentWithPath:@"alovelace"]
addSnapshotListener:^(FIRDocumentSnapshot *snapshot, NSError *error) {
if (snapshot == nil) {
NSLog(@"Error fetching document: %@", error);
return;
}
NSLog(@"Current data: %@", snapshot.data);
}];
val db = Firebase.firestore
// Write
val user = hashMapOf(
"firstname" to "Ada",
"lastname" to "Lovelace"
)
db.collection("users").document("alovelace")
.set(user)
// Read / listen
val docRef = db.collection("users").document("alovelace") docRef.addSnapshotListener { snapshot, e ->
if (e != null) {
Log.w(TAG, "Listen failed.", e)
return@addSnapshotListener
}
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, "Current data: ${snapshot.data}")
} else {
Log.d(TAG, "Current data: null")
}
}
FirebaseFirestore db = FirebaseFirestore.getInstance();
// Write
Map<String, Object> user = new HashMap<>(); user.put("firstname", "Ada"); user.put("lastname", "Lovelace");
db.collection("users").document("alovelace")
.set(user);
// Read / listen
final DocumentReference docRef = db.collection("users").document("alovelace"); docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, "Current data: " + snapshot.getData());
} else {
Log.d(TAG, "Current data: null");
}
}
});
import { getFirestore, doc, setDoc, onSnapshot } from "firebase/firestore";
const db = getFirestore(firebaseApp);
// Write
await setDoc(doc(db, "users", "alovelace"), {
firstname: "Ada",
lastname: "Lovelace",
});
// Read / listen
onSnapshot(doc(db, "users", "alovelace"), (docSnapshot) => {
console.log("Latest data: ", docSnapshot.data());
// ...
});
db = FirebaseFirestore.instance;
// Write
final user = <String, String>{
"firstname": "Ada",
"lastname": "Lovelace"
};
db
.collection("users")
.doc("alovelace")
.set(user)
// Read / listen
final docRef = db.collection("users").doc("alovelace"); docRef.snapshots().listen(
(event) => print("current data: ${event.data()}"),
onError: (error) => print("Listen failed: $error"),
);
// Write
DocumentReference docRef = db.Collection("users").Document("alovelace"); Dictionary<string, object> user = new Dictionary<string, object> {
{ "firstname", "Ada" },
{ "lastname", "Lovelace" }
};
docRef.SetAsync(user);
// Read / listen
docRef.Listen(
snapshot =>
{
IDictionary<string, object> dict = snapshot.ToDictionary();
foreach(var kVPair in dict)
{
Console.WriteLine($"{kVPair.Key}: {kVPair.Value}");
}
}
);
Firestore* db = Firestore::GetInstance();
// Write
db->Collection("users")
.Document("alovelace")
.Set({ {"firstname", FieldValue::String("Ada")},
{"lastname", FieldValue::String("Lovelace")})
// Read / listen
DocumentReference doc_ref = db->Collection("users").Document("alovelace"); doc_ref.AddSnapshotListener(
[](const DocumentSnapshot& snapshot, Error error, const std::string& errorMsg) {
if (error == Error::kErrorOk) {
if (snapshot.exists()) {
std::cout << "Current data: " << snapshot << std::endl;
} else {
std::cout << "Current data: null" << std::endl;
}
} else {
std::cout << "Listen failed: " << error << std::endl;
}
});
Swift
Objective-C
Kotlin+KTX
Java
Dart
Unity
C++
Messaging.messaging().subscribe(toTopic: "/topics/news")
[[FIRMessaging messaging] subscribeToTopic:@"/topics/news"];
Firebase.messaging.subscribeToTopic("news");
FirebaseMessaging.getInstance().subscribeToTopic("news");
await FirebaseMessaging.instance.subscribeToTopic("topic");
Firebase.Messaging.FirebaseMessaging.Subscribe("news");
firebase::messaging::Subscribe("news");
Swift
Objective-C
Kotlin+KTX
Java
Dart
Unity
C++
Analytics.logEvent("share_image", parameters: ["id" : "image123"])
[FIRAnalytics logEventWithName:@"share_image"
parameters:@{@"id": "image123"}];
Firebase.analytics.logEvent("share_image") {
param("id", "image123")
}
Bundle params = new Bundle();
params.putString("id", "image123");
FirebaseAnalytics.getInstance(this).logEvent("share_image", params);
await FirebaseAnalytics.instance.logEvent(
name: "select_content",
parameters: {
"content_type": "image",
"item_id": itemId,
},
);
Firebase.Analytics.FirebaseAnalytics.LogEvent("share_image", "id", "image123");
const firebase::analytics::Parameter kParams[] = { firebase::analytics::Parameter("id", "image123") };
firebase::analytics::LogEvent("share_image", kParams, sizeof(kParams) / sizeof(kParams[0]));
Swift
Objective-C
Kotlin+KTX
Java
JavaScript
Dart
Unity
C++
let storageRef = Storage.storage().reference()
let riversRef = storageRef.child("image/rivers.jpg")
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else { return }
// ...
}
FIRStorage *storage = [FIRStorage storage];
FIRStorageReference *riversRef = [storageRef child:@"images/rivers.jpg"];
FIRStorageUploadTask *uploadTask = [riversRef putData:data
metadata:nil
completion:^(FIRStorageMetadata *metadata,
NSError *error) {
if (error != nil) {
// ...
} else {
// ...
}
}];
val storage = Firebase.storage
storage.child("images/rivers.jpg").putBytes(data)
.addOnFailureListener {
// ...
}.addOnSuccessListener { taskSnapshot ->
// taskSnapshot.metadata contains file metadata such as size, content-type, etc.
// ...
};
FirebaseStorage storage = FirebaseStorage.getInstance();
storage.child("images/rivers.jpg").putBytes(data)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// ...
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// ...
}
});
var storageRef = firebase.storage().ref();
storageRef.child("images/rivers.jpg").put(data).then(function(snapshot) {
// ...
});
final storageRef = FirebaseStorage.instance.ref();
final mountainsRef = storageRef.child("images/mountains");
mountainsRef.putFile(imageData);
FirebaseStorage storage = FirebaseStorage.DefaultInstance;
StorageReference riversRef = storage.GetReference("images/rivers.jpg");
riversRef.PutBytesAsync(customBytes).ContinueWithOnMainThread(task => {
if (!(task.IsCanceled || task.IsFaulted)) {
// Metadata contains file metadata such as size, content-type, and etc.
StorageMetadata metadata = task.Result;
// ...
}
});
firebase::storage::Storage* storage = firebase::storage::Storage::GetInstance(app);
firebase::storage::StorageReference ref = storage->GetReference("images/rivers.jpg");
firebase::Future<firebase::storage::Metadata> result = ref.PutBytes(data, data_size, nullptr, nullptr);
// ...
if (result.Status() == firebase::kFutureStatusComplete) {
if (result.Error() == firebase::storage::kErrorNone) {
// ...
}
}