gpt4 book ai didi

swift - FBSDKGraphRequestHandler Swift 3错误

转载 作者:搜寻专家 更新时间:2023-11-01 05:34:29 26 4
gpt4 key购买 nike

我已经尝试调试我的整个应用程序,目前我只遇到了 3 个错误,都是同样的错误。我花了几个小时尝试自行调试这最后 3 个错误,但没有成功。当然,这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)
}

}



}
}

}
}

出现的错误是:

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

它出现在这行代码中

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

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

谢谢!

最佳答案

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

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

Expression of type 'FBSDKGraphRequestConnection?' is unused

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

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

关于swift - FBSDKGraphRequestHandler Swift 3错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44122328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com