【问题标题】:FBSDKRequestConnection warning swift3FBSDKGRAPHRequestConnection 警告 swift 3
【发布时间】:2016-09-26 21:04:35
【问题描述】:

我已尝试解决此警告,但没有成功。自从升级到 swift3 后,我在我的 Facebook 图形请求完成处理程序中收到一条警告消息。

错误信息具体为“'FBSDKGraphRequestConnection?'类型的表达式未使用。”

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

            if error != nil {

                //do something with error

            } else if result != nil {

                //do something with result 
            }

        })

我尝试添加(在完成处理程序中)如下代码行,以查看警告是否会消失但警告是否持续存在。

connection.start()

connection.timeout = 30

if connection != nil {


            }

我在 swift2 中运行良好的完成处理程序并没有给我这样的警告。我没有正确使用完成处理程序吗?

【问题讨论】:

    标签: xcode facebook-graph-api connection swift3 completionhandler


    【解决方案1】:

    对于任何感兴趣的人,看起来首选的方法是:

    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()
    

    上面似乎比 graphRequest.start() 更受欢迎,没有警告或错误。

    【讨论】:

    • 谢谢,真烦人。
    【解决方案2】:

    你可以像这样简单地删除它

    在 swift 3 中

    _ = request?.start { (connection, result, error) in    
        }
    

    在 swift 2.x 中

    let _ = request?.start { (connection, result, error) in    
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多