I installed the Facebook Swift SDK via Cocoapods:
pod 'FacebookCore', :git => "https://github.com/facebook/facebook-sdk-swift" pod 'FacebookLogin', :git => "https://github.com/facebook/facebook-sdk-swift"
I followed the login instructions from the Facebook Swift SDK ( https://developers.facebook.com/docs/swift/login ), 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 log in via Facebook and then the web view becomes blank and nothing happens. The application is displayed in my Facebook applications, so some authorizations have occurred, but if I click the Finish button in the web view, the result of the callback will be .cancelled and "Userβs canceled login". is printed.
I added key separation to my rights, and I updated my info.plist:
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string> [ FB STRING ] </string> </array> </dict> </array> <key>FacebookAppID</key> <string>[ APP ID ]</string> <key>FacebookDisplayName</key> <string>[ APP NAME ]</string> <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fb-messenger-api</string> <string>fbauth2</string> <string>fbshareextension</string> </array>
I even changed the settings of NSAppTransportSecurity .
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
I know this is a duplicate of iOS 9 Facebook login simulator -canOpenURL: failed URL: "fbauth2: ///" - error: "(null)" and How to use the SDK for iOS for iOS 10 , but none of the solutions seem to be doesn't work for me if I missed something? Any suggestions are welcome.
Several errors are also printed:
[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 application installed on my device, I get:
-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn't be completed. (OSStatus error -10814.)"