首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOS导入错误

IOS导入错误
EN

Stack Overflow用户
提问于 2017-01-03 22:11:17
回答 1查看 367关注 0票数 0

我对IOS非常陌生,我刚刚开始使用Facebook的API-Graph。

现在我想要执行"/me“查询,但是我得到了以下错误:

未解析标识符“GraphRequest”的使用

这是我的密码:

代码语言:javascript
复制
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
....
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {

if ((error) != nil)
{
    // Process error
}
else if result.isCancelled {
    // Handle cancellations
}
else {  
    if result.grantedPermissions.contains("public_profile") && result.grantedPermissions.contains("user_friends") && result.grantedPermissions.contains("user_posts") && result.grantedPermissions.contains("user_photos")
    {
        //HERE IS MY QUERY

        let params = ["fields" : "email, name"]
        let graphRequest = GraphRequest(graphPath: "me", parameters: params)  <-- HERE I GOT THE ERROR
        graphRequest.start {
            (urlResponse, requestResult) in

            switch requestResult {
            case .failed(let error):
                print("error in graph request:", error)
                break
            case .success(let graphResponse):
                if let responseDictionary = graphResponse.dictionaryValue {
                    print(responseDictionary)

                    print(responseDictionary["name"])
                    print(responseDictionary["email"])
                }
            }
        }


                guard let presentedController = self.storyboard?.instantiateViewController(withIdentifier: "01") else { return }
                presentedController.modalTransitionStyle = UIModalTransitionStyle.partialCurl
                self.present(presentedController, animated: true, completion: nil)
            }
        }


        guard let presentedController = self.storyboard?.instantiateViewController(withIdentifier: "01") else { return }
        presentedController.modalTransitionStyle = UIModalTransitionStyle.partialCurl
        self.present(presentedController, animated: true, completion: nil)*/
    }else{
        //cambia stato bottone
        let alert = UIAlertController(title: "Missing Permission", message: "We need all the permission for continue", preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
}
}

我把进口和FB登录做得很好。我做错了什么?(我用Swift 3)

更新2:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-03 22:17:58

GraphRequest应该是FBSDKGraphRequest

代码语言:javascript
复制
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)

注意:除了Swift SDK之外,还有一个Swift特定的https://developers.facebook.com/docs/swift

编辑:

根据您更新的问题,FBSDKGraphRequest似乎可以返回一个可选选项。可选的意思是您将得到FBSDKGraphRequestnil的一个实例。

您可以通过几种不同的方式处理可选选项。

  • 使用guard构造
  • 使用if let构造
  • 使用?

使用guard

代码语言:javascript
复制
guard let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params) else {
    // Handle the fact that graphRequest is nil
}

graphRequest.start { ... } // graphRequest is guaranteed to be not nil

使用if let

代码语言:javascript
复制
if let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params) {
    graphRequest.start { ... } // graphRequest is guaranteed to be not
} else {
    // Handle the fact that graphRequest is nil
}

使用?

代码语言:javascript
复制
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)

graphRequest?.start { ... }

如果graphRequestnil,这将不会有任何作用。

编辑2:

您似乎在使用Facebook方法来调用start方法,而不是使用iOS SDK方式。

FBSDKGraphRequestHandler是用以下参数定义的typedef

  • FBSDKGraphRequestConnection连接
  • id结果
  • NSError错误

因此,在调用start时,需要在闭包中考虑这些参数。

代码语言:javascript
复制
graphRequest.start { connection, result, error in
    ...
}

或者对您不感兴趣的参数使用_

代码语言:javascript
复制
graphRequest.start { _, result, _ in
    ...
}

注意:您的switch语句很可能不适用于上面的代码。您需要进行进一步的更改,以使它能够使用所提供的参数(连接、结果和错误)。同样,您可能正在混合Facebook的Swift代码和iOS SDK代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41453204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档