我一直在通过swift获取用户配置文件信息。 有没有错误,但我想检查此代码是否工作或因为下面的错误,我无法检查模拟器。如何获取Facebook用户配置文件(swift)
错误:退回到存储,因为模拟器错误
据我所知的访问NSUserDefaults的象征,这个错误不会发生在真实的设备。
class FetchUserProfileController: UIViewController {
@IBOutlet weak var userFullName: UILabel!
@IBOutlet weak var userProfileImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
userFullName.text = ""
if let _ = FBSDKAccessToken.current()
{
fetchUserProfile()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func fetchUserProfile()
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id, email, name, picture.width(200).height(200)"])
graphRequest.start(completionHandler: { (connection, result, error) -> Void in
if ((error) != nil)
{
print("Error took place: \(error)")
}
else
{
print("Print entire fetched result: \(result)")
let fbData:[String:AnyObject] = result as! [String : AnyObject]
let userName : NSString? = fbData["name"]! as? NSString
let facebookID : NSString? = fbData["id"]! as? NSString
if let imageURL = ((fbData["picture"] as? [String: Any])?["data"] as? [String: Any])?["url"] as? String {
//Download image from imageURL
}
}
})
}
}