When I click on login with Facebook button, it is opening safari browser and getting closed immediately. Noticed error on the console.
App delegate method:
This is an Xcode warning indicating the the canOpenURL: call returned false. As long as you have configured the
LSApplicationQueriesSchemesentry in your plist as described above, you can ignore this warning.
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)
}
I figured out my issue. It was just the syntax in loginButtonClicked function. The error message was leading me down the wrong path. Here is the working code.
@objc func loginButtonClicked() {
self.login = FBSDKLoginManager()
self.login.logIn(withReadPermissions: ["public_profile"], from: self, handler: {(result, error) -> Void in
if error != nil {
print("Process error")
}
else if (result?.isCancelled)! {
print("Cancelled")
}
else {
print("Logged in")
DispatchQueue.main.async(execute: {
let viewController:UIViewController = self.storyboard?.instantiateViewController(withIdentifier: "UITabBarController") as! UITabBarController
self.present(viewController, animated: true, completion: nil)
})
}
})
}
I have missed the importing FBSDKCoreKit. Later it started working on the simulator but not on the iPhone device.
Also noticed the following FAQ on the Facebook site. Why do I see console messages like
'canOpenURL: failed for URL: "fb...://'
or ? This is a Xcode warning indicating the canOpenURL: call returned false. As long as you have configured the LSApplicationQueriesSchemes entry in your plist as described above, you can ignore this warning
Regarding not working on the iPhone device, please refer: Parse API - Facebook login not working on the iPhone device
I have the same warning, but in Facebook Docs there is an answer.
This is an Xcode warning indicating the the canOpenURL: call returned false. As long as you have configured the LSApplicationQueriesSchemes entry in your plist as described above, you can ignore this warning
https://developers.facebook.com/docs/ios/ios9
You need to add this method if your app is running on iOS9 or above.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
return [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
In case you need a Swift version:
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return SDKApplicationDelegate.shared.application(app,
open: url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation] as Any)
}
If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the Facebook SDK v4.6.0 or above:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
To prepare the facebook integration supported to iOS 9, go through Facebook Integraion for iOS 9 guidelines
To check version of facebook SDK, use below line of code:
print("SDK version \(FBSDKSettings .sdkVersion())")