当用户在ios 13.0中单击登录按钮时,Facebook登录总是被取消,但它在ios 12.0或更快的swift中完全正常工作



注意: 它在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'

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

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

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

最新更新