robertbabington robertbabington - 1 year ago 467
Swift Question

Facebook SDK sign in with Swift 3 iOS 10

I installed Facebook's Swift SDK via Cocoapods:

pod 'FacebookCore', :git => ""
pod 'FacebookLogin', :git => ""

I have followed the login instructions from Facebook's Swift SDK ( but cannot get it working.

Inside my view controller I have the following:

@objc fileprivate func facebookSignIn() {
let loginManager = LoginManager()
print("LOGIN MANAGER: \(loginManager)")
loginManager.logIn([ .publicProfile, .email ], viewController: self) { loginResult in
print("LOGIN RESULT! \(loginResult)")
switch loginResult {
case .failed(let error):
print("FACEBOOK LOGIN FAILED: \(error)")
case .cancelled:
print("User cancelled login.")
case .success(let grantedPermissions, let declinedPermissions, let accessToken):
print("Logged in!")
print("GRANTED PERMISSIONS: \(grantedPermissions)")
print("DECLINED PERMISSIONS: \(declinedPermissions)")
print("ACCESS TOKEN \(accessToken)")

"Login manager: etc." prints when I click the button and the web view opens. I can sign in via Facebook and then the web view goes blank and nothing happens. The app shows in my Facebook apps, so some authorisation has taken place, but if I click the "Done" button in the web view, the result to the callback is
and "User cancelled login." is printed.

I have added Keychain Sharing to my entitlements, and I've updated my info.plist:

<string> [ FB STRING ] </string>
<string>[ APP ID ]</string>
<string>[ APP NAME ]</string>

I've even changed my


I know this is a duplicate of iOS 9 Facebook login simulator -canOpenURL: failed for URL: "fbauth2:///" - error: "(null)" and How to use Facebook iOS SDK on iOS 10 but none of the solutions there seem to work for me, unless I've missed something? Any suggestions are appreciated.

Several errors are printed also:

[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction

[error] error: (6922) I/O error for database at /var/mobile/Containers/Data/Application/F3D8E126-B0CC-4C06-81A5-D7A7F849B3BD/Documents/OfflineModel2.sqlite. SQLite error code:6922, 'disk I/O error'

And when I don't have the FB app installed on my device, I get:

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

Answer Source

You have to substitute didfinishlaunching and openurl AppDelegate methods with below:

public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool 
    return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)

public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool 
    return SDKApplicationDelegate.shared.application(app, open: url, options: options)