iOS应用程式的核心资料,相片& iCloud [英] iOS app with core data, photos & iCloud

查看:199
本文介绍了iOS应用程式的核心资料,相片& iCloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,使用核心数据(使用UIManagedDocument)来存储我想要与iCloud同步的用户生成的数据。我也想在应用内同步用户使用相机拍摄的照片。



我读到在核心数据中存储实际照片不是一个好主意;而是更好地将照片存储在文件系统中,并将fileURL放在核心数据中。



使用此方法,当使用UIDocument在文件系统(文档文件夹)下存储照片时,建议采用什么方法?
我想过:


  1. 对于每张照片,使用NSFileWrapper(包含
    实际映像和

  2. 使用顶层NSFileWrapper,并为每张照片放置所有NSFileWrappers

  3. 与#2类似,但只是将所有照片/缩略图直接放在顶级NSFileWrapper中

哪种方法最适合与iCloud同步照片?并且有更好的方法吗?

解决方案

在这种情况下,最好的办法是让Core Data决定把它放在哪里。 p>

打开您的Core Data模型GUI - 单击将保存您的二进制数据的属性 - 右侧有一个复选框,指示Core Data是否应该如果需要使用外部存储。选择它。



就是这样。如果Core Data需要使用外部存储,它将这样做 - 你既不知道也不关心它决定什么。


I'm developing an app that uses core data (with UIManagedDocument) for storing user-generated data that I would like to sync with iCloud. I also would like to sync photos that the user takes with the camera within the app.

I read that it's not a good idea to store the actual photos within core data; rather it's better to store the photos in the file system and put the fileURL in core data.

Using this method, what is the recommended approach when using UIDocument to store the photos in the file system (under the Documents folder)? I've thought about:

  1. For each individual photo, use a NSFileWrapper(containing the actual image and thumbnail image), or
  2. Use a top-level NSFileWrapper, and put all NSFileWrappers in it for each photo
  3. Similar to #2, but just put all photos/thumbnails directly in the top-level NSFileWrapper

Which approach is better for syncing photos with iCloud? and are there better approaches?

解决方案

The best approach in this case is to let Core Data decide where to put it.

Open your Core Data model GUI -- click on your attribute that will hold your binary data -- look to the right -- there is a check box that indicates if Core Data should use external storage if it wants. Select it.

That's all. If Core Data needs to use external storage, it will do so -- you wil neither know nor care what it decides.

这篇关于iOS应用程式的核心资料,相片& iCloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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