FBSDKGraphRequestHandler Swift 3 错误

FBSDKGraphRequestHandler Swift 3 error

我已经尝试调试我的整个应用程序,目前我有 3 个错误,都是同样的错误。我花了几个小时尝试自行调试这最后 3 个错误,但没有成功。当然,这3个错误都是一样的,而且我知道调试一次就可以全部调试

错误与 Facebook SDK 有关,特别是 FB SDK Graph Request Handler。

这是代码

    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error?) {
            if let error = error {
                print(error.localizedDescription)
                return
            }
            else{
                let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

                // If already anon user exists link with new user
                if Auth.auth().currentUser != nil{
                    Auth.auth().currentUser!.link(with: credential) { (user, error) in
                        // ...
                    }
                }

let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email,first_name, last_name, birthday, gender"], tokenString: FBSDKAccessToken.current().tokenString, version: nil, httpMethod: "GET")

req ? .start(completionHandler: {
            (connection, result, error: NSError!) - > Void in
            if (error == nil) {
                print("result \(result)")
                Auth.auth() ? .signIn(with: credential) {
                    (user, error) in
                    if error != nil {
                        print("Login failed. \(error)")
                    } else {
                        print("Logged in! \(user)")
                        FirebaseUtility.sharedInstance.setUser(user!)

                        let name = String.init(format: "%@ %@", result.value(forKey: "first_name") as!String, result.value(forKey: "last_name") as!String)
                        FirebaseUtility.sharedInstance.editUserValue(name, key: "name")
                        if (result.object(forKey: "gender") != nil) {
                            let gender = result.object(forKey: "gender") as!String
                            FirebaseUtility.sharedInstance.editUserValue(gender.capitalized, key: "gender")
                        }
                        if (result.object(forKey: "email") != nil) {
                            let gender = result.object(forKey: "email") as!String
                            FirebaseUtility.sharedInstance.editUserValue(gender.capitalized, key: "email")
                        }


                        if self.isSignupflow == true {
                            FirebaseUtility.sharedInstance.sendToken()

                            // this user hasn't completed his profile so show him profile page
                            let vc: SignupViewController = SignupViewController(nibName: "SignupViewController", bundle: nil)
                            self.present(vc, animated: true, completion: nil)
                        } else {
                            FirebaseUtility.sharedInstance.isFirstTimeUser {
                                (isFirstTimeUser) in

                                if isFirstTimeUser {
                                    FirebaseUtility.sharedInstance.sendToken()
                                        // this user hasn't completed his profile so show him profile page
                                    let vc: SignupViewController = SignupViewController(nibName: "SignupViewController", bundle: nil)
                                    self.present(vc, animated: true, completion: nil)
                                } else {
                                    // take him into app
                                    //                                self.loginSuccessful()
                                    let vc: RecordViewControllerNew = RecordViewControllerNew(nibName: "RecordViewControllerNew", bundle: nil)
                                    vc.isBackButtonHidden = true
                                    self.present(vc, animated: true, completion: nil)
                                }

                            }



                        }
                    }

                }
            }

发生的错误是:

Cannot convert value of type '(, _, NSError!) ->Void' to expected argument type 'FBSDKGraphRequestHandler!'

它出现在代码的这一行

req ? .start(completionHandler: {
                (connection, result, error: NSError!) - > Void

任何帮助将不胜感激,我知道一旦解决了这个错误,就会产生更多错误,但这就是编码的工作原理:)

谢谢!

FBSDKGraphRequestHandler 具有可选的 Error? 作为最后一个参数而不是 NSError!,因此将完成块从 req?.start(completionHandler: { (connection, result, error: NSError!) - > Void 更改为 req?.start(completionHandler: { (connection, result, error) in 将减少该错误。

此外,在更改此设置后,您会收到新的警告,例如。

Expression of type 'FBSDKGraphRequestConnection?' is unused

所以只需添加 _ = 作为 req?.start 的前缀。

_ = req?.start(completionHandler: { (connection, result, error) in
    //Add your code here  
})