5
簡單的問題。如果我在完成塊內 - 例如使用firebase進行Facebook登錄...並且登錄成功。如果我想從完成塊中關閉當前的視圖控制器(登錄視圖控制器),是否需要返回主隊列來執行此操作。我假設登錄完成塊正在後臺線程完成,任何改變到用戶界面(即解散當前視圖控制器)應該在主線程上完成...這裏最好的做法...或者我錯過了什麼?Swift - 從完成塊中解散視圖控制器
@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)
}
})
}
})
}
同樣的問題我的回答關於performSegue:http://stackoverflow.com/questions/32292600/swift-performseguewithidentifier-not-working/32 292706#32292706 – BaseZen
您必須在主線程上執行此操作。 – ryantxr