Why am I getting com.facebook.sdk.login error 308?

Swinny89 picture Swinny89 · Oct 22, 2015 · Viewed 15.6k times · Source

I am using Xcode 7.0, testing on iOS 9.0.2 and using Facebook SDK 4.7.0.

When I am logging in a user, most of the time everything works as it should, however sometimes I keep getting this error and I have no idea why!

The operation couldn’t be completed. (com.facebook.sdk.login error 308.)

After researching I have seen that some people are getting the error when logging in with parse.com's FBUtils and the official FBSDK at the same time, however I am only using FBSDK in my project.

So my question is, why am I getting this error and how do I get rid of it?

Edit - Adding Code

Here is my login logic:

func loginWithFacebook(sender: UIViewController, completion: (profile: FBSDKProfile?, token: String?, cancelled: Bool, error: String?) -> Void ) {

    FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
    NSNotificationCenter.defaultCenter().addObserver( sender , selector: "onProfileUpdated:", name:FBSDKProfileDidChangeNotification, object: nil)
    let loginManager = FBSDKLoginManager()
    loginManager.logInWithReadPermissions(["email", "public_profile"], fromViewController: sender) { (result: FBSDKLoginManagerLoginResult!, error: NSError!) -> Void in
        if error != nil {
            print("ERROR")
            completion(profile: nil, token: nil, cancelled: false, error: error.localizedDescription)
            print(error.localizedDescription)

        } else if result.isCancelled {
            print("CANCELLED")
            completion(profile: nil, token: nil, cancelled: true, error: nil)

        } else {
            print("NO ERROR")
            if FBSDKProfile.currentProfile() == nil {
                print("PROFILE IS NIL")
                completion(profile: nil, token: result.token.tokenString, cancelled: false, error: nil)
            } else {
                print("PROFILE IS NOT NIL")
                completion(profile: FBSDKProfile.currentProfile(), token: result.token.tokenString, cancelled: false, error: nil)
            }

        }

    }
}

Answer

Mohammad Zaid Pathan picture Mohammad Zaid Pathan · Sep 17, 2016

For Xcode8 - iOS10,

Enable Keychain Sharing within Capabilities tab of target fixed my issue.

enter image description here

More details can be found here : https://github.com/facebook/facebook-sdk-swift/issues/51


For Xamarin Studio (Suggested by @Kenneth),

Add the Entitlements.plist file to Custom Entitlements under the iOS Bundle Signing options in the iOS project.