开发者

Core Data sync between iPhone and iPad

开发者 https://www.devze.com 2022-12-30 22:43 出处:网络
I have a universal iPhone/iPad application that uses Core Data as storage. I would like to enable users to sync the开发者_Go百科ir data between two devices(iPhone , iPod and iPad).

I have a universal iPhone/iPad application that uses Core Data as storage. I would like to enable users to sync the开发者_Go百科ir data between two devices(iPhone , iPod and iPad).

Is there any sample application or code that performs this?


You just need to write a regular Core Data app, and as a general Core-Data-agnostic problem, figure out a good way to package and exchange data between two networked devices.

One way is to use JSON or XML to encapsulate your Core Data entity data being synced between two devices. You could run web servers on both devices to exchange JSON- or XML-encapsulated data.

When the web server receives a request and a bundle of data, it then adds a new entity to the Core Data store, just like any other local application would.

Just search Google or your favorite search engine on "JSON", "XML", and "web services". There are lots of third-party Objective-C frameworks for processing JSON and XML, as well as for making web requests and for receiving them.


To resurrect this question: does the insertion of a new entity preserve relationships that existed in the other persistant store? For example:

The user sets up entity A that has a relationship to entity B (the inverse is true) on the iPhone. The user syncs the app with the iPad version (which has no data) - the only way successfully complete the sync is to insert a new entity A and B whose attributes and relationships are "copied" from the sync'ed entities. Since you've now inserted new managed objects to a new persistant store, would the iPad app have the correct relationships set up?

The Core Data docs make it clear that two managed objects can not belong to multiple persistant stores, and suggets inserting a new object with the same data. However, I'm concerned that by doing this relationships will not be configured correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号