設計簡易的即時多人遊戲傳輸通道 - 透過 Firebase Realtime Database
可靠性通道:嘗試設計多玩家遊戲動作序列
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
}
}];不可靠性通道:嘗試設計公頻聊天系統
Last updated