xcode iOS:Facebook 登录访问令牌错误:由于模拟器错误,退回到从 NSUserDefaults 加载访问令牌

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41047345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:38:12  来源:igfitidea点击:

iOS: Facebook Login access token error: Falling back to loading access token from NSUserDefaults because of simulator bug

iosxcodefacebookfacebook-graph-apiios-simulator

提问by SabCo

After configuring it based on the instructions I keep on getting this error and I am unable to successfully use Facebook Login on my app. I am running it on XCode 8.1 and using an iOS 10.1 simulator.

根据说明对其进行配置后,我不断收到此错误,并且无法在我的应用程序上成功使用 Facebook 登录。我在 XCode 8.1 上运行它并使用 iOS 10.1 模拟器。

I followed the steps on the Facebook iOS SDK guide and put the Facebook login button in my view controller. I displayed the NSUserdefaults and one of the keys is "com.facebook.sdk:serverConfiguration" so I believe it is saving there.

我按照 Facebook iOS SDK 指南中的步骤操作,并将 Facebook 登录按钮放在我的视图控制器中。我显示了 NSUserdefaults,其中一个键是“com.facebook.sdk:serverConfiguration”,所以我相信它保存在那里。

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([FBSDKAccessToken currentAccessToken]) {
        // User is logged in, do work such as go to next view controller.
        NSLog(@"test");
    }
    else {
        FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
        loginButton.center = self.view.center;
        [self.view addSubview:loginButton];
    }
    _loginButton.readPermissions =
    @[@"public_profile", @"email", @"user_friends"];
    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
}

回答by Jorn van Dijk

If the problem is that the iOS Simulator is signed out after a restart of the app, this is caused by a bug in the Facebook SDK. It prevents the simulator from caching the access token.

如果问题是在重新启动应用程序后退出 iOS 模拟器,则这是由 Facebook SDK 中的错误引起的。它可以防止模拟器缓存访问令牌。

You can fix this by adding the following line:

您可以通过添加以下行来解决此问题:

key = [NSString stringWithFormat:@"%@_fix", key];

key = [NSString stringWithFormat:@"%@_fix", key];

in FBSDKKeychainStore.m:94and FBSDKKeychainStore.m:135just before:

FBSDKKeychainStore.m:94FBSDKKeychainStore.m:135之前:

[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

回答by Emilio Barcelos

To get rid of these rather annoying log messages (that's all they are), go to FBSDKCoreKit's FBSDKKeychainStore.mfile and comment lines 93 and 134:

要摆脱这些相当烦人的日志消息(仅而已),请转到 FBSDKCoreKit 的FBSDKKeychainStore.m文件并注释第 93 和 134 行:

//NSLog(@"Falling back to storing access token in NSUserDefaults because of simulator bug");

Voilá... gone!

瞧……走了!

Note:This is current for Facebook SDK for iOS version 4.23.0.

注意:这是适用于 iOS 版本 4.23.0 的 Facebook SDK 的最新版本。

For CocoaPods:The file can be found in your Xcode workspace under:
Pods > Pods > FBSDKCoreKit > FBSDKKeychainStore.m

对于 CocoaPods:该文件可以在您的 Xcode 工作区中找到:
Pods > Pods > FBSDKCoreKit > FBSDKKeychainStore.m