我目前正在使用facebook登录app.And我正在尝试显示用户封面照片和用户个人资料照片。
但在这里,我无法拍摄封面,个人资料照片,也无法在我的图片视图中填充。
这里是我的代码:
func getFacebookGraphAndSegue(token:String) {
guard let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"email,name, first_name, last_name,id,cover,picture.width(100).height(100)"], tokenString: token, version: nil, httpMethod: "GET") else {
print("could not get Facebook user info")
return
}
req.start(completionHandler: { (connection, result, error) in
if(error == nil) {
print("result \(result)")
guard let userInfo = result as? [String: AnyObject] else {print("bad result");return}
let name = userInfo["name"] as? String ?? ""
// let cover = (userInfo["cover"] as? UIImage!)["source"]{
// var coverUrl = cover as? String
//
// }
self.performSegue(withIdentifier: "loginSegue", sender: userInfo)
}
else {
print("error \(error)")
}
})
}
//--------------------------------------------------------------------------------------------
// MARK: - Segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "loginSegue" {
if let vc = segue.destination as? UserViewController {
if let info = sender as? [String: AnyObject] {
let email = info["email"] as? String ?? ""
let name = info["name"] as? String ?? ""
let firstName = info["first_name"] as? String ?? ""
let lastName = info["last_name"] as? String ?? ""
let lbl:String = "\nNAME:\(name)"
print(lbl)
vc.info = lbl
}
}
}
}
以上功能中的注释行是我试图获取封面照片以及我需要显示的个人资料照片。
在我的下一个屏幕中,我只会显示用户名,个人资料照片,封面照片:
@IBOutlet weak var labelUserInfo: UILabel!
@IBOutlet weak var coverpageImage: UIImageView!
@IBOutlet weak var profilePicImage: UIImageView!
var info:String = ""
override func viewDidLoad() {
super.viewDidLoad()
self.labelUserInfo.text = info
}
@IBAction func onLogout(_ sender: UIButton) {
//Facebook Logout
print("on Facebook Logout Tapped")
let loginManager = LoginManager()
loginManager.logOut()
self.performSegue(withIdentifier: "logouSegue", sender: nil)
}
请帮帮我。如何获取封面,配置文件图片显示在我的屏幕/图像视图中。
感谢