iOS facebook 登录问题

Posted

技术标签:

【中文标题】iOS facebook 登录问题【英文标题】:iOS facebook login issue 【发布时间】:2017-08-24 19:48:18 【问题描述】:

我已成功在 ios 应用中集成“Facebook 登录”。但是,它的实现存在一个小问题。

成功登录后,应用程序应理想地显示“主屏幕”。但不是该应用程序在显示“主屏幕”之前显示“登录屏幕”2 秒。

我应该实施什么方法,以便在通过 facebook 应用程序成功登录后显示“主屏幕”而不返回“登录屏幕”?

facebook登录代码如下。

let loginManager = LoginManager()     
loginManager.logIn([.publicProfile, .email], viewController: self)
         (result) in
            switch result
            
            case .failed(let error):
                print("Error")
            case .cancelled:
                print("User cancelled")
            case .success(_,_,_):
                self.getUserInfo
                     userInfo, error in

                        let name = userInfo?["first_name"]
                        let email = userInfo?["email"]

                        let homeVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "homeVC") as! HomeViewController

                        homeVC.name = name as? String
                        homeVC.email = email as? String

                        self.present(homeVC, animated: true, completion: nil)

                
            
        

谢谢

【问题讨论】:

Facebook 刚刚获得用户授权并返回获取信息,您可以分享您的代码以获得更多帮助 【参考方案1】:

在完成块内确保您在主线程上执行 UI 操作:

let loginManager = LoginManager()     
loginManager.logIn([.publicProfile, .email], viewController: self)
     (result) in
        switch result
        
        case .failed(let error):
            print("Error")
        case .cancelled:
            print("User cancelled")
        case .success(_,_,_):
            self.getUserInfo
                 userInfo, error in

                    // puts you back on the main thread
                    DispatchQueue.main.async(execute:  

                        let name = userInfo?["first_name"]
                        let email = userInfo?["email"]

                        let homeVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "homeVC") as! HomeViewController

                        homeVC.name = name as? String
                        homeVC.email = email as? String

                        self.present(homeVC, animated: true, completion: nil)
                    )

            
        
    

【讨论】:

请求返回可能需要 2 秒 - 可能显示微调器

以上是关于iOS facebook 登录问题的主要内容,如果未能解决你的问题,请参考以下文章

iOS Facebook ShareLink 处理干扰 Facebook 登录

如何使用内置的 facebook 帐户在 IOS 中进行 Facebook 登录?

Facebook SDK IOS登录问题

无法在 iOS 上使用 Facebook 登录

Facebook Unity SDK iOS 登录不使用系统级登录,而是使用浏览器或 Facebook 应用程序

安装了 Facebook 应用程序的 Facebook SDK iOS 登录