0
我在查詢Parse以返回用戶創建的所有Tournament對象的列表。但是,saveEventually()
取消了LDS中的對象,因此如果它們具有網絡連接,則查詢將返回空白。使用fromLocalDataStore()和saveEventually進行PFQuery緩存()
override func viewDidLoad() {
super.viewDidLoad()
var query = PFQuery(className:"Tournament")
query.orderByAscending("createdAt")
query.whereKey("createdBy", equalTo: PFUser.currentUser())
query.fromLocalDatastore()
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if (error == nil) {
self.tournaments = objects;
self.tableView.reloadData()
PFObject.pinAllInBackground(objects)
} else {
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
}
我想保留創建的所有對象在本地緩存,以便它們可以脫機訪問。這可能嗎?
如果我們在應用程序離線時調用saveInBackgroundWithBlock,會發生什麼情況?一旦像[saveEventually](https://parse.com/docs/ios_guide#objects-offline/iOS)那樣恢復網絡連接,最終是否會保存它?所有數據都同步到Parse非常重要。 – Fenda 2015-02-18 13:33:54
如果您在用戶離線時調用'saveInBackgroundWithBlock:',則請求將失敗並返回錯誤並解析將不會嘗試重試。 – hhanesand 2015-02-18 19:15:42