How to use Facebook iOS SDK on iOS 10
Asked Answered
C

6

105

I am trying to use Xcode 8 to build a app with Facebook login using Swift 3. When I switch back iOS Simulator 9.3, it works. In iOS 10, I receive this error:

""fbauth2:/" The operation couldn’t be completed. (OSStatus error -10814.)"

and

Optional(Error Domain=com.facebook.sdk.login Code=308 "(null)")

Anyone have solution for this?

Note 1 :

After debugging, this problem is FBSDK cant update expect_challange. Function SecItemUpdate inside security.framework not work. This is a problem of IOS 10

Capitoline answered 1/8, 2016 at 0:44 Comment(1)
"...why would you expect this to work?" Because software should work. It's not this guy's fault, it's not facebook's fault. It's Apple's fault. They get a pass because this is "beta", but breaking the Keychain is near unacceptable, even in beta.Strategist
P
205

Error OSStatus -10814 occures when canOpenURL: can't find any application, that can open this URL (actually, Facebook trying to find their application by calling canOpenURL: with argument "fbauth2:/"). Printing happens inside of function, so you can't do anything with that. But if you will run your application on device with installed Facebook app, you will not see this error.

Error 308 occures because of the situation, when value, stored in keychain is not equal to value, that is stored in facebook completion parameters (for more information you can check -[FBSDKLoginManager completeAuthentication:expectChallenge:]).

It happens because Apple changed the way of working with keychain in iOS 10. To fix this issue you simply should go to Targets->Capabilities and enable keychain sharing (it enables access to keychain for your app): image

If you are using Xamarin (read this link for more information, thanks @dynamokaj):

Just make sure you enable the keychain access in Entitlements and select the entitlements for Simulator (Debug) builds too. By default this is not set.

Photograph answered 5/8, 2016 at 23:48 Comment(32)
thank you very much, Do you have any document about this change ?Capitoline
@Capitoline Unfortunately, I can't find any mention of this change in release notes / documentation.Photograph
for the Error OSStatus -10814, I still see the error when I have facebook app on my iPhone, with a blank screen opening up in my app. You have any idea of what might be happening?Dad
@NikitaP SDK also checks if facebook messenger app or share extension or one more unrecognized for me (fbapi://) are installed.Photograph
@NikitaP when is blank screen appear? Are you sure that it is caused by Facebook SDK?Photograph
@RomanErmolov so whenever the call to FBSDKLoginManager's logInWithReadPermissions:fromViewController:handler: is called, the UI goes to a blank screen + there is no callback to the handler, whether an error or a success, until I hit the done but to implicitly cancel.Dad
We are still having this problem after trying to toggle 'Keychain Sharing' as well. fwiw we are seeing the identical problem happen for Google Sign too. Running Xcode 8 GM with latest FBSDKCoreKit and FBSDKLoginKit and am still seeing this issue.Defeasance
@RoyKolak Just checked with Xcode 8 GM + FBSDKCoreKit 4.15.0 - it works when keychain sharing is enabled. Do you set path to new Xcode with xcode-select?Photograph
After quitting xcode, running, sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer, and trying to rebuild, still getting the same problem. I'm realizing now that the error I am seeing is more similiar to this #39092341Defeasance
@RoyKolak It seems that the problem in the way of presenting SFSafariViewController. Apple added some conditions in iOS 10 that blocks loading request after presenting controller. I am not familiar with this case, but I will take a look if I can reproduce it and will have enough free time.Photograph
@NikitaP it seems that you have experience with the problem that @ RoyKolak mentions above.Photograph
@NikitaP figured it out. It was a third party library (CleverTap) that was trying to auto integrate into the app delegate. I replied in #39092341 Thanks for your attention!Defeasance
@RoyKolak thanks but nothing like that for me. I think the link you have provided mentions a warning of wrong way to add a subview/view controller. That's what my issue might be.Dad
I'm still seeing this 308 issues on SDK 4.15.1 even with key chains enabled. Our app was rejected because the app review team could not login under the new iOS 10 test environment. This wasn't an issue in iOS 9. The error only occurs if there are no native Facebook app installed on the device.Pilkington
@aznxfrost could you please provide test sample, that reproduces your problem? I can't reproduce behavior you are talking about.Photograph
Tks. I had a issue to login using cordova and cordova-plugin-facebook4, and this answer helped me solved it.Dealer
@RomanErmolov, I have keychain sharing enabled from iOS 9, but still getting error -10814. Any ideaHelpmeet
@Helpmeet error -10814 is not connected with keychain sharing, please reread my answer.Photograph
@RomanErmolov - Is your answer only related to device? I am running iOS 10 simulator and device. I can run on device with no problem, but in the simulator I get the 308 error even though I have enabled Keychain Sharing. Also I am in doubt if the keychain sharing should be enabled in App MemberCenter also? I can't see the entry in their.Dicrotic
@Dicrotic nope, it should work on both simulator and device. Yep, I can't find "Keychain Sharing" in MemberCenter too. How do you manage app signing - automatically by Xcode or by manual?Photograph
@RomanErmolov app signing is done in XCode when building in debug for device. However when I build for simulator I do not think that it triggers any signing?Dicrotic
@RomanErmolov I have now installed the iOS 9.3 Simulator in XCode 8 and I can use Facebook login without problems. I will now wait until Facebook releases a new SDK with better support for iOS 10.Dicrotic
@RomanErmolov I figured it out, I am on Xamarin and when building for debug the Entitlement.plist file is not used by default. When I included the Entitlement for debug it worked. The following gave me the final push to a proper solution. https://mcmap.net/q/205743/-xamarin-auth-store-keychain-not-working-after-ios10-upgrade - Maybe you could update your answer to make it easier for the Xamarin dudes to figure out was they are missing.Dicrotic
Excellent solution, it fix my [Error]: PFKeychainStore failed to set object for key 'currentUser', with error: -34018 issue.Shows
How to add keychain sharing to app id if you DON'T have an iOS Device?Sayres
@RohitTigga what do you mean? You don't need a device to enable keychain sharing.Photograph
@RomanErmolov there is a red box that says I don't have keychain sharing with my app id. how to resolve that?Sayres
I tried everything and no luck :/ does anyone have any insight into this? #40032647Sayres
Thanks for explanaitons, it's really helpful @RomanErmolov. What I don't understand is, why do users need to have application installed, can't they also login without having application but facebook account?Obsession
@RomanErmolov, really helpful answer! But, tip me please, how I can catch the error in case when user doesn't have an installed facebook application and handle it. Cause now, error handler doesn't fire and I have exception in SDKSharingDelegateBridge class at didFailWithError method and receive the same 10814 errorShirting
How do you get to Targets? I am running an application through ionic. I cannot find targets in xcode, it wants me to start a new project or workspaceLyso
I am having similar issue com.facebook.sdk.login error 308, and enabling keychain access does not resolved the issue, Any solution ?Misspend
J
5

Same problem was in my app, i checked many solution but did't works for me. I've fix this problem using below method.

Go to this Link Select Your App and configure your info.plist

import and add this code in your AppDelegate

import FBSDKCoreKit
import FBSDKLoginKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}
Jaye answered 30/8, 2017 at 9:53 Comment(0)
S
4

The main reason why you're getting the following error,

canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)

is that your iOS simulator does not have the Facebook Application installed. Until you install the application on your iOS simulator, you will continue to get the error. Try running your iOS application on a provisioned iOS device with Facebook installed and you will not see the error message again. Hope this helps!

Semela answered 18/2, 2017 at 10:0 Comment(1)
It should open the web ui when the fb app is not installed.Mintun
U
3

In my case, the fix was*:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 

  // First, handle Facebook URL open request
  if let fbSDKAppId = FBSDKSettings.appID(), url.scheme!.hasPrefix("fb\(fbSDKAppId)"), url.host == "authorize" { 
    let shouldOpen: Bool = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) 
    return shouldOpen 
  } 

  // After it, handle any other response (e.g. deep links)
  handlerOtherUrls(url: url) 
  return true 
}

*As recommended by @MoridinBG at Facebook SDK's Github page

Urogenous answered 30/8, 2017 at 14:49 Comment(0)
K
0

This error can also be caused if you are using FBSDKCoreKit or FBSDKLoginKit version 4.39.0 . There was a bug in this version of the SDK. Upgrade to 4.39.1 or higher to fix it. Details here.

As a side note, other users mentioned that this error is seen if you don't have Facebook installed on the simulator. That is true, but the SDK is supposed to automatically fall back to the Web login method when the app is not installed. If that doesn't happen it may be caused by another issue such as missing/misconfigured values in your Info.plist (check LSApplicationQueriesSchemes) or missing methods on your AppDelegate.

Keeping answered 16/1, 2019 at 1:2 Comment(0)
E
-3

In my case, the problem was Google Analytics. By default it seems it's adding its own view controller on top of the app's view controller. Setting "FirebaseAppDelegateProxyEnabled" to "NO" in {Your app}-Info.plist solved the problem.

Eads answered 4/10, 2016 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.