简单的问题。如果我在完成块中 - 例如使用 Firebase 进行 Facebook 登录...并且登录成功了。如果我想要从完成块内部取消当前视图控制器(登录视图控制器),我需要回到主队列来执行此操作吗?我假设登录完成块正在后台线程上进行,对 UI 的任何更改(即取消当前视图控制器)都应该在主线程上完成...这里有什么最佳实践...或者我漏掉了什么吗?
@IBAction func facebookLoginTapped(sender: AnyObject) {
//
let ref = Firebase(url: "https://XXXX.firebaseio.com")
let facebookLogin = FBSDKLoginManager()
facebookLogin.logInWithReadPermissions(["email"], fromViewController: self, handler: { (facebookResult, facebookError) -> Void in
if facebookError != nil {
print("Facebook login failed. Error \(facebookError)")
} else if facebookResult.isCancelled {
print("Facebook login was cancelled.")
} else {
//successfully logged in
//get facbook access token
let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
//use access token to authenticate with firebase
ref.authWithOAuthProvider("facebook", token: accessToken,
withCompletionBlock: { error, authData in
if error != nil {
print("Login failed. \(error)")
} else {
//authData contains
print("Logged in! \(authData)")
//pop loginvc back to uservc - DO I NEED TO GET MAIN THREAD HERE BEFORE DISMISSING VIEW CONTROLLER
self.dismissViewControllerAnimated(true, completion: nil)
}
})
}
})
}