RestKit - sending added / edited / deleted objects after offline storage

Using RestKit with basic data I provide offline support when a user adds, edits, or deletes objects without an Internet connection, placing objects and saving them using Core Data.

If the Internet is again available, I will extract all added / edited / deleted objects, save them in arrays and know correctly, use the usual methods and a loop for each element to put them on the server.

Array list
- FetchedAddedCompanies
- FetchedEditedCompanies
- extractedAddedContacts
- 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 submit an object (self.company) with its mapping to the server.

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

Question

I am looking for a more effective solution when the user has updated several objects and, what is special, added several new objects, because unlike all editing / deleting methods, the server returns an identifier for each newly created object that will be saved.

1) Avoid using, for example, updateAccountToServer for each edited object and sending an array of objects instead
2) Using RKRequestQueue together with RKObjectManager (there is a good answer on this question )

In my opinion, 1) it will be difficult to implement, because resourcePath for each request contains a unique identifier, so I tried 2), but missed the opportunity to bind a mapping for each request using

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

Thanks for your ideas!

+4
source share
2 answers

I and some others are actively working on the development branch to automatically integrate it into RestKit.

We are introducing a synchronization manager inside the PK that monitors NSManagedObjectContext for changes, and if the network is unavailable, queue these requests until the network returns.

We would like additional help / ideas in the code, so if you could tell us more about your use case on this page:

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

+1
source

For 1, you can encapsulate the NSArray of inserted / updated / deleted objects in a new object, and then send it to the server. To do this, you need to make sure that the correct bits are set on the modified objects to decrypt the server, and also make sure that the server can receive the object and deconstruct it to obtain an array of modified objects.

+1
source

Source: https://habr.com/ru/post/1404022/


All Articles