【问题标题】:FBSDKGraphRequestHandler Swift 3 errorFBSDKGraphRequestHandler Swift 3 错误
【发布时间】:2017-05-22 21:21:04
【问题描述】:

我尝试调试我的整个应用程序,但目前我发现了 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)
                                }

                            }



                        }
                    }

                }
            }

出现的错误是:

无法将类型 '(, _, NSError!) ->Void' 的值转换为预期的参数类型 'FBSDKGraphRequestHandler!'

它发生在这行代码

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

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

谢谢!

【问题讨论】:

    标签: swift facebook swift3 xcode8 fbsdk


    【解决方案1】:

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

    更改此设置后,您还会收到类似的新警告。

    'FBSDKGraphRequestConnection?' 类型的表达式没用过

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

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

    【讨论】:

      猜你喜欢
      • 2017-03-16
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 2018-10-15
      • 1970-01-01
      • 2017-02-08
      相关资源
      最近更新 更多