Swift:如果删除了子级的观察者,则不调用Firebase身份验证观察者



假设ref = Firebase(url: "your firebase url") .
裁判的孩子将被childRef = ref.childByAppendingPath("child")

如果我ref.observeAuthEventWithBlock在 ref 上侦听身份验证更改,然后我使用 childRef.removeAllObservers() ,则 ref 的身份验证观察者不再侦听更改。

这是为什么呢?

我制作了一个小应用程序来复制问题(遵循 ObjC 代码)

要监视身份验证的代码是:

[myRootRef observeAuthEventWithBlock:^(FAuthData *authData) {
    NSLog(@"got an auth event");
}];

我们有子节点

child = [myRootRef childByAppendingPath:@"child_path"];

那么初始身份验证是

[myRootRef authUser:@"dude@thing.com" password:@"pw" withCompletionBlock:^(NSError *error, FAuthData *authData) {
        NSLog(@"authentication 1 success");
        [child removeAllObservers];
        [self doAuth];
    } 
}];

doAuth 方法只是对另一个用户进行身份验证并输出"身份验证 2 成功"

got an auth event
got an auth event
authentication 1 success
authentication 2 success

因此,如您所见,它像宣传的那样工作 - 我无法复制该问题。我的猜测是错误可能位于代码中的其他地方。

最新更新