我想在viewDidLoad
中调用此函数,但我不知道如何做到这一点。你能帮我吗?
func loginWithFacebook(withcompletionHandler: (success:Bool) ->()){
var permissions : Array = [ "user_location","public_profile"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
println("User SIGNED UP and logged in through Facebook!")
self.fetchUserInforFromFacebook(withcompletionHandler)
println("User logged in through Facebook!")
withcompletionHandler(success: true)
}
} else {
println("Uh oh. The user cancelled the FACEBOOK LOGIN.")
self.showErrorMessage(error!)
withcompletionHandler(success: false)
}
})
}
答案 0 :(得分:2)
如果您在函数中调用函数
override func viewDidLoad() {
super.viewDidLoad()
self.loginWithFacebook { (success) -> () in
// Your code.
}
}
如果你想在同一个函数中调用它,那么
override func viewDidLoad() {
super.viewDidLoad()
loginWithFacebook { (success) -> () in
// Your code.
}
}
答案 1 :(得分:0)
因此,为了调用您的方法,请将其添加到您的viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
self.loginWithFacebook { (success) -> () in
// Your code.
}
}
答案 2 :(得分:0)
override func viewDidLoad() {
super.viewDidLoad()
self.loginWithFacebook { (success) -> () in
if success { //succeeded } else { //failed } }
}
}