2017-05-22 4 views
1

私はアプリケーション全体をデバッグしようとしましたが、現在私は3つのエラー、すべて同じエラーです。私はこの3つのエラーを自分でデバッグしようと何時間もしたが、成功しなかった。もちろん、3つのエラーは同じで、私は1つをデバッグすると知っている、私はそれらのすべてをデバッグすることができますFBSDKGraphRequestHandler Swift 3エラー

エラーはFacebook SDK、特にFB SDKグラフ要求ハンドラに関連しています。

この

はコード

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!) - >ボイド' 期待される引数の型に'FBSDKGraphRequestHandler!'

、それはすべてのヘルプは、私はこのエラーが解決されれば、より多くのエラーを作成しようとしている知って、理解されるだろうが、それは作品をコーディングどれだけのコード

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

のこの行で発生:)

ありがとう!

答えて

0

FBSDKGraphRequestHandlerは、最後の引数はないNSError!として任意Error?を有するので、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 
})