2015-10-27 92 views
0

根據標題,我得到零在我的設備上測試時可選的解包錯誤,而不是模擬器 - 我發現原因是致電FBSDKProfile.currentProfile.name或類似。我記得在模擬器開發過程中,我感到很痛苦,我在用戶登錄時添加了FBSDKProfile.enableUpdatesOnAccessTokenChange(true),並且如果他們已經登錄,在應用程序加載時修復了它。iOS/FBSDK - FBSDKProfile在設備上無效,在模擬器上正常工作

任何人都有這個問題的經驗或對解決方案有任何想法?如果有人認爲它會提供幫助,很高興發佈代碼。

謝謝!

+0

你的模擬器是否有fcebook帳號? –

回答

0

這個問題的原因是FBSDKProfile需要幾秒鐘來加載,我沒有給它時間,因此試圖使用零值。

所以解決方案是有佔位符值,並聽取FBSDK通知FBSDKProfileDidChangeNotification,更新完成後的值。

下面的代碼:

viewDidLoad方法:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("onFBProfileUpdated:"), name: FBSDKProfileDidChangeNotification, object: nil) 

和一個單獨的方法:

func onFBProfileUpdated(notification: NSNotification) { 
    nameLabel.text = FBSDKProfile.currentProfile().name 

    setImage(FBSDKProfile.currentProfile().imageURLForPictureMode(FBSDKProfilePictureMode.Square, size: image.frame.size)) 
} 

希望這有助於人誰在同樣的問題絆倒的我。

相關問題