Swift 3通过userID完成数据传递

时间:2017-03-08 03:52:38

标签: ios firebase swift3 firebase-authentication

我尝试对Firebase进行检查以查看用户是否存在,然后我需要在继续之前检查特定的值。我目前有这个:

func myFirebaseNetworkDataRequest(finished: () -> Void) {
    if let user = FIRAuth.auth()?.currentUser {
                self.userUUID = (user.uid)
                getUser(userUUID: self.userUUID)
                finished()
    }
}

在我看来,确实加载了:

myFirebaseNetworkDataRequest {

        // perform further operations here after data is fetched
        if AppState.sharedInstance.user == true  {
                    //present 1st view controller 
        } else {
                    //present 2nd view controller
        }

在我的" getUser"功能:

func getUser(userUUID: String) {
    let userFacebookRef = FIRDatabase.database().reference(withPath: "users").child(userUUID)
    //The rest of the Firebase function. 

    AppState.sharedInstance.user == results.active
    //active is = to true

目前发生的是,如果出现第二个视图控制器,因为firebase已经完成了。我知道我需要一个块,因为firebase已经是asnyc但是如何通过闭包/块发送userUUID?

1 个答案:

答案 0 :(得分:0)

你可以让你的闭包参数有一个自己的参数。像,

func myFirebaseNetworkDataRequest(finished: (_ isAuthenticated: Bool) -> Void)

然后在你的viewDidLoad中,你会提出你的请求......

open override func viewDidLoad() {
    self.myFirebaseNetworkDataRequest( (isAuthenticated) -> {
        if isAuthenticated {
            // Present VC1
        } else {
            // Present VC 2
        }
    }
}