Note : It is working fine in ios < 12.0 but when I run the application on the ios 13.0 then it shows the log in the console that "User cancelled login".

I don't know what could be the reason for this. Can anyone help me?

Maybe it can be ios 13.0 compatibility issue of facebook login. Here I attach a couple of my code's snippet with info.plist and pod specific version.

Here is the code of Appdelegate.swift


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
            return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
        }

info.plist

    <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
            <key>NSAllowsArbitraryLoadsForMedia</key>
            <true/>
            <key>NSAllowsArbitraryLoadsInWebContent</key>
            <true/>
        </dict>

This is the function, where I can handle the response "User cancelled login"

class func loginWithFacebook(controller: UIViewController, completionHandler: @escaping (_ result: Bool) -> Void){
        //.. Code process
        let defaults = UserDefaults.standard
        if defaults.value(forKey: "FBToken") != nil
        {
            let jsonData : [String : Any] = defaults.value(forKey: "FBDict") as? [String : Any] ?? [String: Any]()
            print(jsonData)

            completionHandler(true) // return data & close
        }
        else{
            let loginManager = LoginManager()
            loginManager.logIn(readPermissions: [ .publicProfile,.email,.userGender, .publicProfile, .userBirthday,
            ], viewController: controller) { loginResult in

                switch loginResult {
                case .failed(let error):
                    print(error)
                case .cancelled:
                    print("User cancelled login.")
                case .success(let grantedPermissions, let declinedPermissions, let accessToken):
                    print(grantedPermissions)
                    print(declinedPermissions)
                    print(accessToken)
                    Utility.getFacebookUserData(completionHandler: { (success) in
                        if success == true{
                            completionHandler(true)
                        }
                        else{
                            completionHandler(false)

                        }// return data & close
                    })

                    break
                }
            }
        }
    }

pod file have :

pod 'FBSDKCoreKit', '~> 4.44.1'
pod 'FBSDKLoginKit', '~> 4.44.1'
pod 'FacebookCore', '~> 0.6.0'
pod 'FacebookLogin', '~> 0.6.0'
pod 'FacebookShare', '~> 0.6.0'

If you have any reference link then also share it here...

1

There are 1 best solutions below

0
Bogy On

This issue is discussed here: https://github.com/facebookarchive/facebook-swift-sdk/issues/482#issuecomment-548656310

Version 5.8.0 fix the issue for me, try to update your Facebook dependencies (latest version is 5.11.1 as I'm writing)