可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
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.
回答2:
The solution below works for iOS9 + running on Xcode 8, for Swift3.0
The steps are
- Setup Facebook Launch
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
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)
- Fix Keychain permission issue as shown in the image below
回答3:
You should enable Keychain Sharing on the Capabilities tab.
回答4:
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>
回答5:
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)"
回答6:
My solution on Xcode7.1, Swift2.0
Step 1. Clean your build folder: option
+ command
+ K
or: Choose Product
> Clean
Step 2. Clean your derived data: Choose Window
> Projects
:
and then choose Delete
:
回答7:
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.
回答8:
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.
回答9:
In my case it was fixed by updating to latest FB SDK. 4.10 at the moment.
回答10:
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.
回答11:
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...)
回答12:
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>
回答13:
In the FBSDKDelegate Method loginButtonWillLogin put this
- (BOOL) loginButtonWillLogin:(FBSDKLoginButton *)loginButton{
[FBSDKAccessToken setCurrentAccessToken:nil];
return YES;}
回答14:
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!
回答15:
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.
回答16:
To Resolve this issue you needs to just enable "Keychain Sharing" in capabilities.
回答17:
I followed Suraj Pathak with Xcode 9.4.1 and Swift 4.2
Add to AppDelegate didFinishLaunchingWithOptions
SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
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)
}
Allow Keychain in Capabilities.
回答18:
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.