57

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.

Leo
  • 24,596
  • 11
  • 71
  • 92
Jude Michael Murphy
  • 1,198
  • 2
  • 12
  • 23
  • Code would definitely be necessary, there is not enough information in your question to give any recommendation. BTW, doing a quick search, I found this http://stackoverflow.com/questions/30643122/ios-parse-facebook-login-error-308-fbsdkloginbadchallengestring. Not sure if it's your same issue but I guess it wouldn't hurt to check. – curveorzos Jun 10 '15 at 04:58
  • have you looked at this? http://stackoverflow.com/a/31480026/383919 – coco Jul 17 '15 at 16:07
  • Same error on xcode 7.1 ios 9.1 FB SDK 4.7.1 – jonypz Oct 27 '15 at 19:56
  • 1
    This is the workaround that worked for me: http://stackoverflow.com/a/33683799/877225 – ObjSal Nov 13 '15 at 00:13
  • I just exchanged my FB SDK frameworks with the latest ones worked for me! – Anurag Sharma Mar 03 '17 at 12:16

18 Answers18

48

The solution below works for iOS9 + running on Xcode 8, for Swift3.0

The steps are

  1. Setup Facebook Launch

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

  1. Setup Open Url

    guard let source = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String else { return false } let annotation = options[UIApplicationOpenURLOptionsAnnotationKey] as? String return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)

  2. Fix Keychain permission issue as shown in the image below

iOS 9 Keychain fix

Suraj Pathak
  • 910
  • 8
  • 9
44

One solution, at least for me, is to not run on device via the Xcode debugger. If I run the app on device outside the debugger the Facebook login works fine. If I run the app in the sim via the debugger the Facebook login works fine.

Only if I run the app on device via the Xcode debugger do I get the com.facebook.sdk.login error 308 every time.

user3633673
  • 594
  • 6
  • 6
  • 1
    This doesn't work - you can run from a device detached from the debugger, and logging out of FB and attempting to login can trigger this scenario. Running FB SDK 4.6.0 – Shaun Jan 12 '16 at 00:04
  • thanks, After running app on device without Xcode-Debugger.... i am able to debug also – kalpesh jetani Feb 23 '16 at 05:05
  • It still happens as of 20160223 using facebook ios sdk 4.10.0 on iOS 9.2. – chubao Feb 23 '16 at 06:17
42

You should enable Keychain Sharing on the Capabilities tab.

Di B.
  • 1,009
  • 10
  • 11
27

I had exactly the same problem and was able to find the solution by modifying the Info.plist

I've added all the possible schemes to LSApplicationQueriesSchemes

The complete list looks like this:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb</string>
    <string>fb-messenger-api20140430</string>
    <string>fb-messenger-platform-20150128</string>
    <string>fb-messenger-platform-20150218</string>
    <string>fb-messenger-platform-20150305</string>
    <string>fb-messenger-api</string>
    <string>fbshareextension</string>
</array>
Stas Zhukovskiy
  • 799
  • 9
  • 21
  • This seemed to have fixed the issue for me too. I'm using SDK 4.7 and their instructions specifically say you shouldn't need this whole list once you upgrade to 4.6 or later. Oh well, glad it's working! – Chad Pavliska Oct 19 '15 at 21:36
  • 1
    Actually it stopped working without any apparent reason – Andrespch Oct 24 '15 at 11:14
  • 1
    Yes it worked first and now I am getting the same error again. Anybody got a permanent solution for SDK 4.7 ? – ShayanK Nov 05 '15 at 23:38
  • Facebook changed a lot of stuff internally when iOS 9.1 came out to correctly handle situations with associated domains. Perhaps, this answer stopped working, however it still works in a project I'm currently working on. – Stas Zhukovskiy Nov 06 '15 at 21:16
  • I would not rely on that, seeing that lots of strings use dates in the name, that's going to break any time ... – TheEye Feb 03 '16 at 12:21
  • @TheEye, your probably right. The answer was relevant at that time, but Facebook has released several versions of their SDK and it's not a problem anymore. – Stas Zhukovskiy Feb 03 '16 at 21:28
  • This is working for me as well. The chosen answer to "not debug" is not really an appropriate solution, IMHO. – Tony Heupel Feb 09 '16 at 16:44
14

I'm getting the exact same thing FB SDK 4.6.0 Xcode 7.0 iOS9. All the setup & instructions on the facebook developer site were followed to the letter. None of the above solutions worked for me. I'm finding that the behaviour is worse when you're deploying to the device live and feeding back to the Xcode console while doing the login procedure. It's really pot luck if it actually logs you in or not. It seems to behave in a more predictable way when you just re-launch your app cold after deployment. -Yes this is in fact the case!

When it decides to fail to login it results in the following error:

Error Domain=com.facebook.sdk.login Code=308 "(null)"
Geoff H
  • 3,107
  • 1
  • 28
  • 53
  • 7
    me too, FBSDK 4.6.0 & Xcode 7.0 & iOS9. I've successfully logged in for the 1st time, but after I logout, I cannot login any more. I've tried to uninstall and reinstall the app, use different FB accounts, but with NO luck. The same binary works good on iOS7 and iOS8 devices. – Dong Ma Sep 24 '15 at 11:56
  • Same here first login works great, subsequent ones all fail with Error Domain=com.facebook.sdk.login Code=308 "(null)"... None of the solutions above worked – sachadso Sep 28 '15 at 10:11
  • To debug the app and overcome the issue, I have set `Launch` to be `Wait for executable to be launched` in scheme settings. No debug console logging but at least I have the breakpoint hits. – Yevhen Dubinin Oct 16 '15 at 02:52
5

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

Tai Le
  • 8,530
  • 5
  • 41
  • 34
4

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.

edsancha
  • 89
  • 9
  • 1
    This was the issue after changing the bundle identifier - refreshing system credentials worked – Shaun Dec 02 '15 at 01:07
4

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.

Community
  • 1
  • 1
kball
  • 4,923
  • 3
  • 29
  • 31
  • Fantastic solution, its the explanation behind why the accepted answer is right. I wasn't happy with simply "Don't run the debugger" and this gives me peace of mind. Good work! +1 – Unome Feb 17 '16 at 04:40
1

In my case it was fixed by updating to latest FB SDK. 4.10 at the moment.

AlexeyVMP
  • 2,386
  • 3
  • 24
  • 31
0

I fixed the problem by uninstalling the app and re-installing and it worked right away.

The error is probably related to iOS 9. Since iOS 9, I think the SDK uses SafariViewController and it seems to create issues when you are already logged.

Gabriel Cartier
  • 1,734
  • 20
  • 22
0

I was able to get login working again on iOS9 with SDK 4.6.0 by adding the new plist key/value

<key>FacebookDisplayName</key>
<string>{Your App Name}</string>

Source code.

I also took the steps in some other answers here to implement a shared FBSDKLoginManager() instance.

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
swift taylor
  • 610
  • 5
  • 10
0

I was getting the same error on xcode 7.1 ios 9.1 FB SDK 4.7.1. .

Uninstalling, installing and testing without xcode works fine for the first time. This will allow you to plug back in the device and run it at least a couple of times (it seems to be a bit inconsistent...)

jonypz
  • 1,515
  • 1
  • 20
  • 35
0

Same problem FB SDK 4.5.1 and none of the above solutions worked for me. I solved this by adding Bolts framework to project by drag & drop (from FacebookSDK directory)
and then adding bolts framework to appDelegate

    #import <bolts/bolts.h>
Kong Hantrakool
  • 1,865
  • 3
  • 20
  • 35
0

In the FBSDKDelegate Method loginButtonWillLogin put this

- (BOOL) loginButtonWillLogin:(FBSDKLoginButton *)loginButton{
[FBSDKAccessToken setCurrentAccessToken:nil];
return YES;}
manu_inup
  • 1
  • 1
0

Updating to the latest (4.11) FB SDK fixed this for me as well. Don't forget to clean your project after updating to see if it works for you!

SlickDev
  • 607
  • 7
  • 7
0

To Resolve this issue you needs to just enable "Keychain Sharing" in capabilities.

Bhavesh Patel
  • 596
  • 4
  • 17
0

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.

blyscuit
  • 616
  • 7
  • 12
0

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.

Elad Cohen
  • 79
  • 9