0

注意:它在 ios < 12.0 中运行良好,但是当我在 ios 13.0 上运行应用程序时,它会在控制台中显示“用户取消登录”的日志。

我不知道这可能是什么原因。谁能帮我?

也许它可能是 facebook 登录的 ios 13.0 兼容性问题。在这里,我附上了一些带有 info.plist 和 pod 特定版本的代码片段。

这是 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)
        }

信息列表

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

这是功能,我可以在其中处理“用户取消登录”的响应

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 文件有:

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'

如果您有任何参考链接,请在此处分享...

4

1 回答 1

0

这个问题在这里讨论:https ://github.com/facebookarchive/facebook-swift-sdk/issues/482#issuecomment-548656310

版本 5.8.0 为我解决了这个问题,尝试更新您的 Facebook 依赖项(我正在写的最新版本是 5.11.1)

于 2019-11-29T10:55:43.923 回答