((Xcode 10)对于Facebook SDK,将Graph API从Swift 3转换为Swift 5

问题描述 投票:0回答:1

我正在开发一个允许用户使用Facebook登录的应用程序。我的代码段使用的是swift 3 tho,但是我找不到在线转换器。快捷的3代码如下:

在示例3中,Xcode建议:

request.start(completion: ((HTTPURLResponse?, GraphRequestResult<GraphRequest>) -> Void)?)

然后程序员进入(这是整个功能):

func getUserInfo(completion: @escaping (_ : [String: Any]?, _ : Error?) -> Void) {

    let request = GraphRequest(graphPath: "me", parameters: ["fields" : "id,email,picture"])

    request.start { response, result in

        switch result {
        case .failed(let error):
            completion(nil, error)
        case .success (let graphResponse):
            completion(graphResponse.dictionaryValue, nil)
        }
    }

当我开始键入:

request.start

我仅获得以下选项:

enter image description here

哪个给我这行代码:

request.start(completionHandler: GraphRequestBlock?)

有人可以帮我将它从Swift 3转换为Swift 5吗?谢谢!

ios facebook-graph-api swift3 facebook-sdk-4.0 swift5
1个回答
0
投票
GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
                if error == nil{
                    //everything works print the user data
                    if let userInfo = result as? [String: Any] {
                        if let email = userInfo["email"] as? String {
                            let firstName = userInfo["first_name"] as? String
                            let lastName = userInfo["last_name"] as? String
                            //Do your operations here.
                        }
                    }
                }
            })

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.