gpt4 book ai didi

ios - graphRequest.start 不返回任何数据

转载 作者:行者123 更新时间:2023-11-28 06:32:48 27 4
gpt4 key购买 nike

我正在使用 Facebook SDK 通过 Swift 3 登录 iOS。

这是我的代码。问题是没有返回任何值。

import UIKit

类 View Controller :UIViewController {

@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!
@IBOutlet weak var uLoginButton: UIButton!

let loginButton: FBSDKLoginButton = {

let button = FBSDKLoginButton()

button.readPermissions = ["email"]

return button;

}()

override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(loginButton);
loginButton.center = view.center
loginButton.delegate = self

if (FBSDKAccessToken.current() != nil) {
fetchProfile();
}

self.style()
}

func fetchProfile(){

let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "email, name, first_name, last_name, picture.type(large)"])

let connection = FBSDKGraphRequestConnection()

connection.add(graphRequest, completionHandler: { (connection, result, error) in

if error != nil {

//do something with error
print("No Data returned")
print(result)
} else {

//do something with result
print("Data returned")
print(result)

}

})

connection.start()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func style(){
self.email.layer.cornerRadius = 15;
self.password.layer.cornerRadius = 15;
self.uLoginButton.layer.cornerRadius = 15;

}

扩展 ViewController : FBSDKLoginButtonDelegate{

internal func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {

// when the login is correct!
print("Success login!");
fetchProfile()
}

internal func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
FBSDKAppEvents.activateApp()
}

internal func loginButtonWillLogin(_ loginButton: FBSDKLoginButton!) -> Bool {
return true
}

最佳答案

在 Swift 3 中,这就是您想要执行图形请求的方式。

  1. 初始化FBSDKGraphRequest
  2. 初始化FBSDKGraphRequestConnection
  3. 添加请求以请求连接
  4. 开始连接。

所以,

let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "email"])
let connection = FBSDKGraphRequestConnection()
connection.add(graphRequest, completionHandler: { (connection, result, error) in

if error != nil {

//do something with error

} else {

//do something with result

}

})

connection.start()

关于ios - graphRequest.start 不返回任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39840648/

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