我正在尝试创建个人资料注册页面,并在从“使用Facebook登录”页面进行调整后从Facebook分配图像。但是在这条线上......
let userID = FBSDKAccessToken.currentAccessToken().userID
......有时候它的工作非常出色,但有时会返回'nil',而我正在
' 2015-04-16 15:08:41.195 FacebookLogin[65906:4225996] [Error]: invalid session token (Code: 209, Version: 1.7.1)
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb) '
以下是完整代码:
override func viewDidLoad() {
super.viewDidLoad()
if let currentUser = PFUser.currentUser() {
let accessToken = FBSDKAccessToken.currentAccessToken()
let userID = FBSDKAccessToken.currentAccessToken().userID
println(userID)
let url = NSURL(string: "https://graph.facebook.com/"+userID+"/picture?width=300&height=300")
let urlRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue(), completionHandler: {
response, data, error in
let image = UIImage(data: data)
self.profilePicture.image = image
currentUser.saveInBackground()
})
}
}
如何找到解决方法?
答案 0 :(得分:3)
我遇到了同样的问题
尝试添加这些
self.fbLoginButton.delegate = self
FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
答案 1 :(得分:2)
您应该从didFinishLaunchingWithOptions
返回此内容返回FBSDKApplicationDelegate.sharedInstance()。application(application,didFinishLaunchingWithOptions:launchOptions)