简体   繁体   English

iPhone应用程序之间的核心数据存储共享

[英]Core Data Store Sharing between iPhone Apps

Is it possible to share a core data store between two different iPhone apps signed by the same developer? 是否可以在同一个开发人员签署的两个不同的iPhone应用程序之间共享核心数据存储? I would like to develop an application where one iPhone app will save a stream of data, which can then be read by the other app. 我想开发一个应用程序,其中一个iPhone应用程序将保存数据流,然后可以由其他应用程序读取。 Is this even possible? 这甚至可能吗? Thanks a lot! 非常感谢!

No, that's not possible. 不,那是不可能的。 An iPhone application runs in a sandbox and though doesn't have access to another applications data store. iPhone应用程序在沙箱中运行,但无法访问其他应用程序数据存储。

Edit: 编辑:

After reading the others answers here: Yes, Custom URLs are possible. 在这里阅读其他答案后:是的,可以使用自定义URL。 And yes it's possible to transfer data with it, but, I, in my opinion, wouldn't recommend this procedure to transfer more than 5kb of data. 是的,它可以用它传输数据,但是,我认为,我不建议这个程序传输超过5kb的数据。 There is no failsafe: No transactions and no relations. 没有故障保险:没有交易也没有关系。

Now in iOS 5 with iCloud you can register both apps with the same iCloud URL. 现在在带有iCloud的iOS 5中,您可以使用相同的iCloud URL注册这两个应用程序。 On initialization of the second app, the core data store of the first is more/less copied into the second. 在初始化第二个应用程序时,第一个应用程序的核心数据存储更多/更少地复制到第二个应用程序。 This can take while---so you need to start the persistent store controller in a background thread, or you app will be killed by a watchdog timer. 这可能需要一段时间---所以你需要在后台线程中启动持久性存储控制器,否则你的应用程序将被看门狗定时器杀死。

However, there are a few caveats. 但是,有一些警告。

  • It doesn't seem to work completely correctly. 它似乎没有完全正确地工作。 Some records form the core data database do not seem to be copied. 一些记录形成的核心数据数据库似乎没有被复制。 In my experience it seems random which records do not make it. 根据我的经验,似乎随机的记录没有成功。 Maybe it is related to to consistency of the original store. 也许它与原始商店的一致性有关。

  • afterwards, the tho apps do not seem to stay in sync, contrary to the same app on two different iDevices. 之后,这两个应用似乎没有保持同步,这与两个不同的iDevices上的相同应用程序相反。

Debugging is a bit of a pain, as it takes 10--20 seconds before a change from one iDevice is transferred to another, and apparently indefinitely before a change from one app on the same iDevice makes it to another app registered with the same iCloud URL. 调试有点痛苦,因为从一个iDevice转换到另一个iDevice需要10到20秒,并且显然无限期地从同一个iDevice上的一个应用程序进行更改之前将其转移到使用相同iCloud注册的另一个应用程序URL。

So in summary---you can copy most records using iCloud on init of the second app, but it is hard to keep them in sync. 总而言之 - 你可以在第二个应用程序的init上使用iCloud复制大多数记录,但很难让它们保持同步。

This can be done using a custom url scheme on the iphone, with some caveats. 这可以使用iphone上的自定义url方案来完成,但有一些注意事项。

If you use a custom url scheme, only one app "owns" the data. 如果您使用自定义网址方案,则只有一个应用“拥有”数据。 The other app would have to import data from the main app... Mobile Orchard did an article on this for moving data from a lite app to a paid for app 另一个应用程序必须从主应用程序导入数据... Mobile Orchard做了一篇关于将数据从精简版应用程序移动到付费应用程序的文章

http://www.mobileorchard.com/lite-to-paid-iphone-application-data-migrations-with-custom-url-handlers/ http://www.mobileorchard.com/lite-to-paid-iphone-application-data-migrations-with-custom-url-handlers/

But I recently came across an MIT licensed library called "SwapKit" that may do exactly what you want as well... Sounds good from the overview on their site, though I haven't tried it: 但是我最近遇到了一个名为“SwapKit”的麻省理工学院许可库,它可能完全符合您的要求...听起来很不错,但我还没有尝试过:

http://infinite-labs.net/swapkit/ http://infinite-labs.net/swapkit/

and this may or may not be of any help, but check out "SpyPhone" too: 这可能有也可能没有任何帮助,但也可以查看“SpyPhone”:

SpyPhone shows the kind of data a rogue application can collect in a non jailbroken iPhone. SpyPhone显示了流氓应用程序可以在非越狱iPhone中收集的数据类型。

http://github.com/nst/SpyPhone http://github.com/nst/SpyPhone

You could use a custom URL scheme to send the data to the second App. 您可以使用自定义URL方案将数据发送到第二个应用程序。

-t -t

There's also the system pasteboard (I think it's NSPasteboard or something, no time to check right now) which is basically the clipboard. 还有系统粘贴板(我认为它是NSPasteboard或其他东西,现在没时间检查),这基本上就是剪贴板。 I think you can put stuff on it and then launch another app with a URL that tells the other app to check the pasteboard. 认为你可以把东西放在上面,然后启动另一个带有URL的应用程序,告诉其他应用程序检查粘贴板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM