我正在尝试使用FBSDKGraphRequest填充textFields。名字/姓氏和电子邮件不是问题,但是当涉及到位置时,我似乎可以做的就是得到德克萨斯州的奥斯汀'。我似乎无法将各个值输出到textFields中。
在下面的代码中,城市textField填充了德克萨斯州的奥斯汀'。我怎么能够得到这个城市'奥斯汀'然后在状态textField得到'德州'
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, location"]).start(completionHandler: { (connection, result, error) -> Void in
if let error = error {
self.alertTheUser(title: "Error", message: error.localizedDescription)
print(error)
}else{
let fbDetails = result as! NSDictionary
let location : NSDictionary! = fbDetails.value(forKey: "location") as! NSDictionary
print(fbDetails)
self.registerEmailField.text = fbDetails.value(forKey: "email") as? String
self.registerFirstNameField.text = fbDetails.value(forKey: "first_name") as? String
self.registerLastNameField.text = fbDetails.value(forKey: "last_name") as? String
self.registerCityField.text = location.value(forKey: "name") as? String
}
})
答案 0 :(得分:0)
忘了清除这个。
FBSDKGraphRequest中的位置应如下所示。
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, location{location}"]).start(completionHandler: { (connection, result, error) -> Void in
然后,您可以单独访问各个位置值。
let locationContents: NSDictionary! = location.value(forKey: "location") as! NSDictionary
self.registerCityField.text = locationContents.value(forKey: "city") as? String
self.registerStateField.text = locationContents.value(forKey: "state") as? String
self.registerCountryField.text = locationContents.value(forKey: "country") as? String