使用GameKit在iPhone之间传输CoreData数据 [英] Using GameKit to transfer CoreData data between iPhones

查看:154
本文介绍了使用GameKit在iPhone之间传输CoreData数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想通过Core Data在两个iPhone之间交换信息。

I have an application where I would like to exchange information, managed via Core Data, between two iPhones.

有没有人试过这个,如果是这样,是这样做的最佳方法(即,人们在文件中使用诸如XML或JSON之类的中间格式,或者可以直接传送对象)。

Has anyone attempted this and if so what is deemed to be the best approach to doing so (i.e. are people using some intermediate format such as XML or JSON in a file or can the objects be transfered directly).

我的道歉,如果问题出现太多boroad范围,但我在阶段,我需要决定一个方法的转移,我没有经验的API。

My apologies if the question appears too boroad in scope but I'm at the stage where I need to decide on an approach for the transfer and I Have no experience of this API.

我非常感谢任何代码示例或链接到任何这样的示例,使用GameKit在设备之间传输对象。

I would be extremely grateful for any code samples, or links to any such sample, for transferring objects between devices using GameKit.

推荐答案

您不能在设备之间直接传输Core Data对象,因为它们链接到其上下文和持久存储。您需要将数据转换为中间格式(可以简单到NSDictionary变成NSData),然后在连接上推送,然后在另一端重新构建数据。

You can't transfer Core Data objects directly between devices because they are linked to their context and persistent stores. You would need to translate the data into an intermediary format (can be as simple as a NSDictionary that gets turned into NSData) and push that across the connection and then reconstitute the data on the other side.

我个人觉得JSON对于这种类型的情况是很好的,因为你可以很容易地将Core Data对象图转换为一组JSON可消费对象(字典,数组,字符串和数字) 。

Personally I feel that JSON is great for this type of situation because you can easily turn the Core Data object graph into a set of JSON consumable objects (dictionaries, arrays, strings and numbers) which can easily be moved around.

这篇关于使用GameKit在iPhone之间传输CoreData数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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