【发布时间】:2019-03-02 00:37:21
【问题描述】:
我在数据库引用上有一个onDisconnectRemoveValue,用于显示用户当前“正在聊天”的时间,并且我想在用户离开聊天视图控制器时断开与 FIRDatabase 的连接 - 我如何在没有完全退出应用?
FIRDatabaseReference *connectedRef = [self.dbRef child:@".info/connected"];
[connectedRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
if (snapshot.value) {
NSString *path = [NSString stringWithFormat:@"connections/%@/participants",self.refID];
FIRDatabaseReference *participantsRef = [self.dbRef child:path];
[participantsRef setValue:@{@"avatar":@"avatarURL",@"handle":[self senderDisplayName]} withCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) {
[ref onDisconnectRemoveValue];
}];
}
}];
【问题讨论】:
标签: ios objective-c firebase firebase-realtime-database