【问题标题】:Swift: Firebase auth observer not called if observers of child removedSwift:如果孩子的观察者被移除,则不会调用 Firebase 身份验证观察者
【发布时间】:2016-02-13 08:52:17
【问题描述】:

假设ref = Firebase(url: "your firebase url")
ref 的孩子是childRef = ref.childByAppendingPath("child")

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

这是为什么?

【问题讨论】:

    标签: ios iphone swift authentication firebase


    【解决方案1】:

    我制作了一个小应用程序来复制问题(后面的 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
    

    所以你可以看到它像宣传的那样工作 - 我无法复制这个问题。我的猜测是错误可能在您的代码中的其他地方。

    【讨论】:

    • 好的,将检查其他可能的原因。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多