[英]Saving Object With Relation Parse.com not PFUser CurrentUser
[英]PFUser currentUser not saving in iOS7
我正在使用以下代碼使用自定義字段保存當前登錄的用戶。 我允許用戶填寫信息,然后保存。 我使用GCM在自己的線程中使用了兩種保存方法,並使用了saveInBackgrounWithBlock。 在iOS8上,此方法可以正常運行,但在iOS7上,永遠不會保存,也不會調用完成塊。 有任何想法嗎? 謝謝
if PFUser.currentUser() != nil {
PFUser.currentUser().setObject(installation, forKey: "installation")
PFUser.currentUser().saveInBackgroundWithBlock({ (bool: Bool, error: NSError?) -> Void in
if(error != nil) {
let alert = UIAlertView(title: "Problem Saving", message: "Make sure you are connecte to the internet and try again", delegate: nil, cancelButtonTitle: "OK")
alert.show();
}
})
}
更新1:我注意到刪除該應用程序可以暫時解決該問題。 但是,注銷並與其他用戶登錄后(即更改當前用戶),該問題將再次彈出。
更新2:問題似乎是由PFInstallation引起的。 使用addUniqueObject會導致問題。 調用此方法后,所有保存都將停止運行iOS7。 即使在PFUser上。 PFUser具有安裝設置,反之亦然。 他們的數組。
更新3:似乎不僅是addUniqueObject,而且還有PFInstallation.currentInstallation上的任何setObject。 救命!
您還應該檢查第一個參數(isSuccess):
if (bool == YES && error != nil) -> success
else -> failure
我花了很長時間才意識到,盡管我從未真正找到解決問題的方法,但還是找到了解決方法。 我將currentUser保存在currentUser中,將currentInstallation保存在currentUser中。 保存時這會引起問題。 我還通過直接發送通道數組而不是使用addUniqueObject來將通道保存在currentInstallation中。
let installation = PFInstallation.currentInstallation()
installation.channels = channels;
installation.saveInBackground()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.