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

陌路散爱 提交于 2019-12-04 07:52:37

问题


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)
            }

        }

    }
}

回答1:


For Xcode8 - iOS10,

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

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.




回答2:


I found the solution to this problem. I was creating an instance of the login manager where i needed it:

let loginManager = FBSDKLoginManager()

Then i was using it to login and I was creating another instance in my logout method. I fixed the issue by creating a lazy variable to be used throughout the app:

lazy var fbLoginManager: FBSDKLoginManager = {
   return FBSDKLoginManager()
}()

UPDATE

Facebook are aware of the bug and are looking into it. I have found that my solution doesn't always work and have updated my code to the following and have not seen it since:

private var _fbLoginManager: FBSDKLoginManager?

var fbLoginManager: FBSDKLoginManager {
    get {
        if _fbLoginManager == nil {
            _fbLoginManager = FBSDKLoginManager()
        }
        return _fbLoginManager!
    }
}

When logging out of Facebook, you need to call _fbLoginManager = nil and the instance will be recreated when it is used to log in the next time. The issue seems to happen more often when using the same instance to log back in after logging out yet the issue happens even more when there are multiple instances of FBSDKLoginManager so declaring it as stated above seems to have fixed the issue.




回答3:


October 2018.

Reason: "+" sign is replaced by " " in challengeReceived string. Issue in FBSDK.

Quick and dirty fix: https://github.com/facebook/facebook-objc-sdk/pull/922

Specifically, replace line 233 in FBSDKLoginManager:

NSString *challengeExpected = [self loadExpectedChallenge];

with

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



回答4:


Looks like problem is solved with 4.9.0. I had the same problem and it's fixed with new SDK version.
https://developers.facebook.com/docs/ios/change-log-4.x




回答5:


Fix available in facebook-objc-sdk https://github.com/facebook/facebook-objc-sdk/releases/tag/sdk-version-4.38.1 and above.




回答6:


I also had this error the reason was in my case: AuthentificationController on which was Facebook login button was presented without navigation controller. To resolve this error i just added navigation controller and sat my AuthentificationController as root.



来源:https://stackoverflow.com/questions/33284453/why-am-i-getting-com-facebook-sdk-login-error-308

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!