Swift Objective-C Java Android Kotlin + KTX Android JavaScript C ++ Unity
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) {
// ...
}
}];
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();
// ...
}
}
});
val auth = Firebase.auth;
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val user = task.result.user
// ...
}
}
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);
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;
}
}
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);
}
});
Swift Objective-C Java Android Kotlin + KTX Android JavaScript C ++ Unity
let ref = Database.database().reference()
// Write
ref.child("users/(userId)").setValue(user)
// Read / listen
ref.child("users").observe(.value) { snapshot in
let dict = snapshot.value as? [String : AnyObject] ?? [:]
// ...
}
FIRDatabaseReference *ref = [[FIRDatabase database] reference];
// write
[[[ref child:@"users"] child:userId] setValue:user];
// read / listen
[[ref child:@"users"] observeEventType:FIRDataEventTypeValue
withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSDictionary *dict = snapshot.value;
// ...
}];
FirebaseDatabase database = FirebaseDatabase.getInstance()
// write
database.child("users").child("userId").setValue(user);
// read / listen
database.child("users").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
val database = Firebase.database
// write
database.child("users").child("users").setValue(user);
// read / listen
database.child("users").addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
// ...
}
override fun onCancelled(databaseError: DatabaseError) {}
});
var database = firebase.database();
// write
database.ref('users/' + userId).set(user);
// read / listen
database.child("users").on('value', function(snapshot) {
// ...
});
// value database callback implementation
class MyDatabaseValueListener: public firebase::database::ValueListener {
virtual void OnValueChanged(const firebase::database::DataSnapshot& snapshot) override {
}
virtual void OnCancelled(const firebase::database::Error& error, const char* error_message) override {
}
};
// implementation
firebase::database::Database* db = firebase::database::Database::GetInstance(app);
// write
db->GetReference("users").Child("userId").SetValue(user->uid());
// read / listen
firebase::database::ValueListener* listener = new MyDatabaseValueListener(); // inherits from ValueListener db->GetReference("users").AddValueListener(listener);
FirebaseDatabase database = FirebaseDatabase.DefaultInstance;
// write
database.RootReference.Child("users").Child(userId).Child("username").SetValueAsync(name);
// read / listen
database.GetReference("users").ValueChanged += HandleValueChanged;
void HandleValueChanged(object sender, ValueChangedEventArgs args) {
if (args.DatabaseError == null) {
// Do something with the data in args.Snapshot...
}
}
Swift Objective-C Java Kotlin + KTX C ++ Unity
Messaging.messaging().subscribe(toTopic: "/topics/news")
[[FIRMessaging messaging] subscribeToTopic:@"/topics/news"];
FirebaseMessaging.getInstance().subscribeToTopic("news");
Firebase.messaging.subscribeToTopic("news");
firebase::messaging::Subscribe("news");
Firebase.Messaging.FirebaseMessaging.Subscribe("news");
Swift Objective-C Java Android Kotlin + KTX Android C ++ Unity
Analytics.logEvent("share_image", parameters: ["id" : "image123"])
[FIRAnalytics logEventWithName:@"share_image"
parameters:@{@"id": "image123"}];
Bundle params = new Bundle();
params.putString("id", "image123");
FirebaseAnalytics.getInstance(this).logEvent("share_image", params);
Firebase.analytics.logEvent("share_image") {
param("id", "image123")
}
const firebase::analytics::Parameter kParams[] = { firebase::analytics::Parameter("id", "image123") };
firebase::analytics::LogEvent("share_image", kParams, sizeof(kParams) / sizeof(kParams[0]));
Firebase.Analytics.FirebaseAnalytics.LogEvent("share_image", "id", "image123");
Swift Objective-C Java Android Kotlin + KTX Android JavaScript C ++ Unity
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 {
// ...
}
}];
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) {
// ...
}
});
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.
// ...
};
var storageRef = firebase.storage().ref();
storageRef.child("images/rivers.jpg").put(data).then(function(snapshot) {
// ...
});
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) {
// ...
}
}
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;
// ...
}
});