2015-05-10 33 views
1

我正在使用下面的代碼來保存當前登錄的用戶自定義字段。我允許用戶填寫信息並保存。我在使用GCM的自己的線程上使用了兩種保存方法,並使用saveInBackgrounWithBlock。在iOS8上,這可以正常工作,但在iOS7上保存不會發生,並且永遠不會調用完成塊。有任何想法嗎?由於PFUser currentUser不保存在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。幫幫我!

回答

0

我花了很長一段時間才能實現,即使我從來沒有真正找到了解決問題本身,我發現了一個解決方法。我正在將當前用戶保存在當前用戶的當前安裝和當前安裝中。這在保存時會導致問題。我還通過直接發送一組通道而不是使用addUniqueObject來保存currentInstallation上的通道。

let installation = PFInstallation.currentInstallation() 
    installation.channels = channels; 
    installation.saveInBackground() 
0

,你應該檢查你的第一個參數(isSuccess)以及:

if (bool == YES && error != nil) -> success 
else -> failure 
+0

該應用程序甚至沒有對第一個if語句進行檢查。它會卡在儲蓄中。只是注意到刪除應用程序暫時解決了這個問題。這似乎是在退出並與其他用戶登錄後發生的。即PFUser currentUser改變。更新問題 – ChrisBorg

相關問題