FBSDK Login Error Code: 308 in Objective-C

2019-03-08 09:51发布

I keep getting

"Error Domain=com.facebook.sdk.login Code=308 "The operation couldn’t be completed. (com.facebook.sdk.login error 308.)""

upon trying to login with Facebook from my device.

My code works on the simulator, but not on an actual device. Has anyone ran into this error code before? I'll be more than happy to share code upon request.

18条回答
萌系小妹纸
2楼-- · 2019-03-08 10:04

If you are using FBSDK 4.38 there is a bug with the parsing of challengeExpected in FBSDKLoginManager.m.

I found a hot fix of rinat-enikeev for it:

https://github.com/facebook/facebook-sdk-swift/issues/286

https://github.com/facebook/facebook-objc-sdk/pull/922/commits/bcf7f787e92320a6322fb3f6130fdc3815bbafb7

Just change

NSString *challengeExpected = [self loadExpectedChallenge];

to

NSString *challengeExpected = [[self loadExpectedChallenge] stringByReplacingOccurrencesOfString:@"+" withString:@" "];

Thats solved the issue for me.

查看更多
再贱就再见
3楼-- · 2019-03-08 10:06

I had the same problem and fixed it refreshing the system credentials

[FBSDKLoginManager renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {

    [[[YourAuthManager manager] facebookLoginManager] logInWithReadPermissions:@[@"email"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {

        if (error) {
            // Handle error
        } else if (result.isCancelled) {
            // Handle cancellations
        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
            }
        }
    }];
}];

This solution is less radical than reinstalling and you assure your users won't have to do it. My guess is that FBSDK 4.6 has some conflicts with iOS 9 system FB authentication credentials.

Edited: After some time testing it kept happening, not as often as before but it was still an issue, so we downgraded to a previous version of FB SDK. Hopefully someone finds a better solution.

查看更多
神经病院院长
4楼-- · 2019-03-08 10:06

In the FBSDKDelegate Method loginButtonWillLogin put this

- (BOOL) loginButtonWillLogin:(FBSDKLoginButton *)loginButton{
[FBSDKAccessToken setCurrentAccessToken:nil];
return YES;}
查看更多
放荡不羁爱自由
5楼-- · 2019-03-08 10:07

My solution on Xcode7.1, Swift2.0

Step 1. Clean your build folder: option + command + K

or: Choose Product > Clean

enter image description here

Step 2. Clean your derived data: Choose Window > Projects: enter image description here

and then choose Delete: enter image description here

查看更多
戒情不戒烟
6楼-- · 2019-03-08 10:08

I followed Suraj Pathak with Xcode 9.4.1 and Swift 4.2

  1. Add to AppDelegate didFinishLaunchingWithOptions

    SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    
  2. Add to AppDelegate delegate function

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return SDKApplicationDelegate.shared.application(app, open: url, options: options)
    }
    
  3. Allow Keychain in Capabilities.

查看更多
Deceive 欺骗
7楼-- · 2019-03-08 10:09

Did some digging around in FBs code and it looks like this is simply an entitlements issue.

FB uses the keychain to store an authorization challenge during login. When returning it attempts to get the value from the keychain and fails. See this SO answer for more info.

Security entitlements can change between provisioning profiles, and as we all know, keeping our profiles and build configurations and devices/sims straight is like herding cats. This could explain why people experience such inconsistent behavior.

So it might be safe to assume that in a production environment, everything will work fine, and if things aren't working during testing then you need to double-check the entitlements on your provisioning profiles.

查看更多
登录 后发表回答