2017-10-19 68 views
1

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

     } 
    }) 
} 

}

回答

0

您的代碼應該正常的設備上運行。 Facebook登錄SDK阻止iOS模擬器緩存訪問令牌。如果您沒有真實設備並且需要在模擬器上檢查登錄,請執行以下操作:

1)在您的項目中搜索FBSDKKeychainStore.m:

2)進入管線94,並添加key = [NSString stringWithFormat:@"%@_fix", key];之前[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

3)進入管線135,並添加相同,key = [NSString stringWithFormat:@"%@_fix", key];之前[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

它仍然會打印你所提到的錯誤線,但你將可以使用模擬器的Facebook登錄

相關問題