-2

我想调用这个函数,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)
            }
        })
    }
4

3 回答 3

1

如果你用 in 函数调用函数

override func viewDidLoad() {
    super.viewDidLoad()
    self.loginWithFacebook { (success) -> () in
        // Your code.
    }
}

如果你想在同一个函数中调用它

override func viewDidLoad() {
    super.viewDidLoad()
    loginWithFacebook { (success) -> () in
        // Your code.
    }
}
于 2015-05-14T07:59:49.673 回答
0

因此,为了调用您的方法,请将其添加到您的viewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()
    self.loginWithFacebook { (success) -> () in
        // Your code.
    }
}
于 2015-05-14T07:52:06.830 回答
0
override func viewDidLoad() {
   super.viewDidLoad()
   self.loginWithFacebook { (success) -> () in
     if success { //succeeded } else { //failed } }
   }
}
于 2015-05-14T07:57:28.617 回答