问题描述
我刚刚修改了我的代码库以使用新的 facebook-ios-sdk 3.0(来自之前的版本、2.x 或其他版本).
I just overhauled my codebase to use the new facebook-ios-sdk 3.0 (from the previous version, 2.x or whatnot).
一切都很好,直到我意识到我没有考虑已经授予应用程序权限/使用 SDK 的先前实现登录的用户.所以我尝试检查 accessToken 是否保存在 NSUserDefaults 中,如果是,则调用以打开会话:
Everything worked great, until I realized I hadn't accounted for users who had already granted the app permission/logged in with the previous implementation of the SDK. So I tried checking to see if the accessToken was saved in NSUserDefaults, and if so, make a call to open a session:
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"FBAccessTokenKey"] &&
[[NSUserDefaults standardUserDefaults] objectForKey:@"FBExpirationDateKey"]) {
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// deal with state change
}
我的假设是用户不必为 SSO 快速切换应用程序,因为他们已经有了.然而,事实确实如此.
My assumption was that the user wouldn't have to fast app switch for SSO, since they already had. However, that is indeed what happens.
我不想让所有现有用户在升级时都需要重新登录.
I'd rather not have every existing user need to re-login when upgrading.
有没有人成功升级而无需重新登录?
Has anyone successfully upgraded without having to re-login?
谢谢
推荐答案
我已经使用 facebook SDK 3.0 升级了一个应用程序,它运行得很好.Facebook SDK 自行处理令牌,但您仍然可以访问 accessToken.
I have upgraded an app with the facebook SDK 3.0 and it worked just fine. The Facebook SDK handles the token itself, but you can still access the accessToken.
您可以随时访问它:
NSString *accessToken = [FBSession activeSession].accessToken;
如果没有设置令牌,这将返回 accessToken 或 nil.您甚至可以在会话上定义令牌缓存规则集.享受.
This will return the accessToken or a nil if no token is set. You can even define a token caching ruleset on the session. Enjoy.
这篇关于将现有的访问令牌迁移到 Facebook iOS SDK 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!