无法在我的 iOS9 应用程序中打印 FBSDKAccessToken.currentAccessToken().tokenString

编程入门 行业动态 更新时间:2024-10-27 19:15:10
本文介绍了无法在我的 iOS9 应用程序中打印 FBSDKAccessToken.currentAccessToken().tokenString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在 Swift 中为 iOS 9 创建一个应用程序以用于学习目的.当我通过我的应用程序登录 Facebook 时,我试图打印 Facebook 的当前访问令牌.

I was creating an app in Swift for iOS 9 for learning purposes. I was trying to print the current access Token of Facebook at time when I log into Facebook through my app.

当我单击 fblogin 按钮时,它会打开 Safari 并显示我已经授权了我的应用程序,但是当我单击确定"时,它卡在 Safari 页面上并且没有按应有的方式打印令牌.它说:

When I click the fblogin button it opens Safari and shows me that I already have authorized my app but when I click okay it stuck on the Safari page and doesn't print the token as it should. And it says :

致命错误:解包可选值时意外发现 nil

fatal error: unexpectedly found nil while unwrapping an Optional value

我使用的是 XCode 7.3.1.我正在添加代码的图片:

I am using XCode 7.3.1. I am adding the pic of the code:

推荐答案

可能是此时在完成处理程序中,FBSDKAccessToken.currentAccessToken() 尚未保存,这就是原因它仍然是 nil.您可以在 FBSDKLoginManagerLoginResult 上使用 @property (copy, nonatomic) FBSDKAccessToken *token; 属性:

It might be that at this point in the completion handler, the FBSDKAccessToken.currentAccessToken() isn't saved yet, that's why it's still nil. You can use the @property (copy, nonatomic) FBSDKAccessToken *token; property on FBSDKLoginManagerLoginResult:

FBSDKLoginManager().logInWithReadPermissions(["email"], fromViewController: self) { (facebookResult: FBSDKLoginManagerLoginResult!, facebookError: NSError!) in
  if let token = facebookResult.token.tokenString {
    print(token)
  }
}

这篇关于无法在我的 iOS9 应用程序中打印 FBSDKAccessToken.currentAccessToken().tokenString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-24 12:32:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1063913.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   FBSDKAccessToken   tokenString   currentAccessToken

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!