我一直在通過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
}
}
})
}
}