ios - Swift:通过 Facebook 应用捕获 Facebook 登录事件

标签 ios swift facebook authentication

我在我的应用程序中实现了 FB 登录,它会打开一个 WebView,如果用户通过 WebView 登录,则一切正常。 Facebook 将返回我可以使用的结果

使用 WebView 的工作代码:

fbLoginManager.logIn(withReadPermissions: ["public_profile","email"], from: UIApplication.shared.keyWindow?.rootViewController?.presentedViewController) { (result, error) in
        if (error == nil){
            let fbloginresult : FBSDKLoginManagerLoginResult = result!
            if fbloginresult.grantedPermissions != nil {
                if(fbloginresult.grantedPermissions.contains("email"))
                {
                    self.getFBUserData()
                    fbLoginManager.logOut()
                }
            }
        }
        else
        {
            FBSDKLoginManager().logOut()
            print(error)
        }
    }

但是,如果用户没有通过WebView登录,而是选择“使用Facebook应用程序登录”选项,我如何获取Facebook应用程序登录的结果?

最佳答案

我也遇到了同样的问题。仅当我使用自定义登录按钮时才会出现 并调用FBSDKLoginManager的logIn方法

如果我使用:

let loginButton = FBSDKLoginButton()
    loginButton.delegate = self

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {

}

问题解决了,我有Facebook应用登录的结果。

您可以轻松自定义FBSDKLoginButton。

关于ios - Swift:通过 Facebook 应用捕获 Facebook 登录事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44421365/

相关文章:

ios - 在没有 App Store ID 的情况下测试 iOS 'Deep Linking'

ios - 试图画一个实心圆但它有黑色背景

iphone - 有没有办法通过浏览器通过 iPhone 捕获图片?

swift - 为什么我不能在类/静态方法中使用 private,internal,fileprivate 方法?

javascript - 在多个域上使用 facebook 应用程序 ID

php - 在 PHP 中使用 RegEx 从 URL 获取 Facebook 视频 ID 的多种变体

ios - 将项目转换到两个选项之一

ios - 如何在 tableview cell swift 中自定义和实现 slider

c++ - OpenCV从2D像素获取3D坐标

swift - 利用 Swift 实现此排序集算法的更惯用方法是什么?