在ViewController之间设置属性值不起作用

时间:2018-03-07 15:45:26

标签: ios swift viewcontroller

我正在尝试使用facebook SDK构建Facebook登录功能。现在我登录viewcontroller与facebook登录按钮和配置文件viewcontroller,点击按钮后将显示。有一些项目需要在个人资料视图控制器中显示,如profilephoto,名称等,这些信息可以从Facebook回复得到,所以我的计划是通过"简介"从登录viewcontroller到profile viewcontroller的数据,下面是登录viewcontroller中的示例代码。

我现在的问题是我找到了"个人资料"内部没有传递数据" DispatchQueue.main.async"下面,当我在其他viewcontrollers中使用segue(覆盖func prepare)时,数据传递工作,不知道为什么不在子线程中工作,任何人都可以帮我解决这个问题,非常感谢

 if let accessToken=FBSDKAccessToken.current(){
        print("FB permissions:\(accessToken.permissions)")

        let graphRequest=FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id,name,email"])
        let connection=FBSDKGraphRequestConnection()
        connection.add(graphRequest, completionHandler:
            {(connection,result,error) in
                let data = result as! [String:AnyObject]
                let name = data["name"] as! String
                let id = data["id"] as! String
                //let email = data["email"] as! String

                print("inside the calling...name:\(name)")

                self.profile?.name=name
                //self.profile?.email=email
                if let url=URL(string:"https://graph.facebook.com/\(id)/picture?type=large&return_ssl_resources=1"),
                    let dataImage = try? Data(contentsOf:url){
                    self.profile?.profilePhoto=UIImage(data:dataImage)
                }

                DispatchQueue.main.async {
                    let homeVC=self.storyboard?.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController
                    homeVC.profile=self.profile
                    self.navigationController?.pushViewController(homeVC, animated: true)

                    self.dismiss(animated: true, completion: nil)
                }
        } )
        connection.start()
    }

0 个答案:

没有答案