FIRDatabaseReference* ref = [[[FIRDatabase database] reference] child:@"Game/UUID GAME ID/Action"];
NSString *key = [ref childByAutoId].key;
NSDictionary *action = @{
@"UserID": @"USER ID A",
@"Action": "Hit",
@"Value": 50,
@"Time": [FIRServerValue timestamp]};
NSDictionary *childUpdates = @{[@"/" stringByAppendingString:key]: action};
[_ref updateChildValues:childUpdates];
FIRDatabaseReference* ref = [[[FIRDatabase database] reference] child:@"Game/UUID GAME ID/Action"];
FIRDatabaseHandle handle = [ref observeEventType:FIRDataEventTypeChildAdded
withBlock:^(FIRDataSnapshot* _Nonnull snapshot) {
if (snapshot.value != [NSNull null]) {
// 監聽 ChildAdded
}
}];
FIRDatabaseReference* ref = [[[FIRDatabase database] reference] child:@"Game/UUID GAME ID/Action"];
[ref observeSingleEventOfType:FIRDataEventTypeValue
withBlock:^(FIRDataSnapshot* _Nonnull snapshot) {
if (snapshot.value != [NSNull null]) {
// 取得 Action Sanpshot
}
}
withCancelBlock:^(NSError* _Nonnull error){
// 失敗
}];
FIRDatabaseReference* ref = [[[FIRDatabase database] reference] child:@"Game/UUID GAME ID/Chat/Public"];
NSDictionary* message = @{
@"UserID" : @"USER ID A",
@"Name" : @"USER NAME",
@"Image" : @"IMAGE URL",
@"Time" : [FIRServerValue timestamp]
};
[_ref updateChildValues:message];
FIRDatabaseReference* ref = [[[FIRDatabase database] reference] child:@"Game/UUID GAME ID/Chat/Public"];
FIRDatabaseHandle handle = [ref observeEventType:FIRDataEventTypeChildChanged
withBlock:^(FIRDataSnapshot* _Nonnull snapshot) {
if (snapshot.value != [NSNull null]) {
// 監聽最新聊天訊息
}
}];