RestKit - 在离线存储后发送添加/编辑/删除的对象 [英] RestKit - Send added/edited/deleted objects after offline storage

查看:142
本文介绍了RestKit - 在离线存储后发送添加/编辑/删除的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用RestKit与Core Data当用户通过标记对象并使用Core Data保存对象来添加,编辑或删除没有互联网连接的对象时,我会提供离线支持。



如果互联网再次可用,我将获取所有添加/编辑/删除的对象,将它们保存在数组中,并知道使用正常的方法并循环每个项目将它们放在服务器上。



数组列表

- fetchedAddedCompanies

- fetchedEditedCompanies

- fetchedAdded对话

- fetchedEditedContacts

- fetchedDeletedContacts



Init方法(已编辑公司的示例)

  //新增公司
...

//编辑公司
(公司* tempObj in fetchedAddedCompanies)
{
//找到所选语言的键
[self updateAccountToServer:tempObj:addCompanyContext];
}

// ...

updateAccountToServer 我发布对象(self.company)并映射到服务器。

 。 .. 
[objectManager postObject:self.company mapResponseWith:[companyMapper inverseMapping] delegate:self];
...



问题



我正在寻找一个更有效的解决方案,当用户更新了一些对象,并且 - 特殊的 - 添加了一些新的对象,因为与所有编辑/删除方法相比,服务器为每个新创建的ID返回一个将被存储的对象。



1)避免使用eg updateAccountToServer,并发送对象数组

2)使用 RKRequestQueue RKObjectManager 关于此问题和一个好回答



在我看来,1 )将很难实现,因为每个请求的resourcePath包含一个唯一的ID,所以我试过2),但缺少绑定映射的每个请求使用

$ b $的可能性b

  [syncQueue addRequest:[[RKObjectManager sharedManager] objectLoaderWithResourcePath:tempString delegate:self]];感谢您的建议!



我们正在实现一个同步管理器



我们希望有更多的帮助/想法,我们希望有更多的帮助/想法如果您可以在此页面上更详细地介绍您的用例:



https://github.com/RestKit/RestKit/pull/573


Using RestKit with Core Data I'm providing offline support when the user adds, edits or deletes objects without an internet connection by flagging the objects and saving them with Core Data.

If the internet is available again, I'll fetch all added/edited/deleted objects, save them in arrays and right know use the normal methods and loop for each item to put them on the server.

List of arrays
- fetchedAddedCompanies
- fetchedEditedCompanies
- fetchedAddedContacts
- fetchedEditedContacts
- fetchedDeletedContacts

Init method (Example for edited companies)

// Added Companies
...

// Edited Companies
for (Company *tempObj in fetchedAddedCompanies)
{
    // Find keys for selected languages
    [self updateAccountToServer:tempObj:addCompanyContext];
}

// ...

At the end of updateAccountToServer I post the object (self.company) with it's mapping to the server.

...
[objectManager postObject:self.company mapResponseWith:[companyMapper inverseMapping] delegate:self];
...

Question

I'm searching for a more efficient solution when the user did update a few objects and - that the special one - did add a few new objects because in contrast to all editing/deleting methods the server returns an ID for each new created object that will be stored.

1) Avoid using e.g. updateAccountToServer for each edited object and send an array of objects instead
2) Using the RKRequestQueue together with the RKObjectManager (regarding this question and a good answer)

In my opinion 1) will be hard to implement because the resourcePath for each request contains a unique ID, so I've tried 2) but missing the possibility to bind the mapping for each request using

[syncQueue addRequest:[[RKObjectManager sharedManager] objectLoaderWithResourcePath:tempString delegate:self]]; 

Thanks for your ideas!

解决方案

Myself and a few others are actively working on a development branch to integrate this into RestKit automatically.

We are implementing a synchronization manager inside of RK that watches the NSManagedObjectContext for changes, and if the network is unavailable, queues those requests until the network comes back.

We'd love to have more help/ideas on the code, so if you could tell us more about your use case on this page:

https://github.com/RestKit/RestKit/pull/573

这篇关于RestKit - 在离线存储后发送添加/编辑/删除的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆