如何通过NSFileManager正确管理iCloud文件? [英] How do I properly manage iCloud files via NSFileManager?

查看:170
本文介绍了如何通过NSFileManager正确管理iCloud文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NSFileManager上的iCloud方法(没有文档或文件协调器)将iCloud同步添加到我的iOS/Mac应用程序.该应用需要在各个实例之间同步音频文件;创建,删除和元数据更改.它不是一个协作风格的应用程序,因此我不太担心冲突等问题.我有一些基本的工作原理,但是遇到了一些基本问题,而这些问题似乎我找不到确切的答案.

I am attempting to add iCloud synching to my iOS/Mac app by using the iCloud methods on NSFileManager (no documents or file coordinators). The app needs to synch audio files across the various instances; create, delete and metadata changes. It isn't a collaboration style app, so I am not very worried about conflicts, etc. I have something basic working, but have run into some basic questions that I can't seem to find definitive answers to.

  1. 使用iCloud时,涉及两个本地目录,即文件所在的沙箱目录和无处不在的容器目录.一旦启用了普遍存在的文件,是应该直接与普遍存在的容器中的文件进行交互,还是应该继续与沙盒文件进行交互并从普遍存在的对等方推送/拉取更改?感觉后者是最好的,这样我就不会丢失所有关闭iCloud的用户文件(不确定那种情况下普遍存在的容器中的文件会发生什么).

  1. When using iCloud, there are two local directories involved, the sandbox directory where the file originates and the ubiquity container directory. Once I enable a file for ubiquity, should I start interacting with the file in the ubiquity container directly or should I continue interacting with the sandbox file and pushing/pulling changes from the ubiquity counterpart? It feels like the latter is best so that I don't lose all the users files if they turn iCloud off (not sure what happens to files in ubiquity container in that case).

如果我维护两个文件,是否有一种首选方法将增量更改推入/拉到普适容器或从普适容器中拉出?据我了解,如果用户更改给定设备上的文件,则所有其他设备都会在其本地无处不在副本(如果已下载)中获得增量更改.每当遍在文件更改时,我是否应该将整个文件全部复制到本地沙箱目录中,反之亦然?

If I maintain two files, is there a preferred way to push/pull incremental changes to/from the ubiquity container? As I understand it, if a user changes a file on a given device, all other devices get the incremental changes in their local ubiquity copy (if downloaded). Should I just be copying the file in it's entirety over to my local sandbox directory every time the ubiquity file changes and vice versa?

推荐答案

在修改文件后不断地将文件复制到无处不在的容器对我来说似乎不是一个好策略,甚至可能导致iCloud认为更多文件具有比真正的改变了.您可以直接与无处不在容器中的文件进行交互,就像在常规"文档沙箱中的文件一样与它们进行交互.这是所有iCloud文档中规定的模型,尽管可能很少.

Constantly copying files to the ubiquity container as they are modified doesn't seem like a good strategy to me and might even result in iCloud thinking more of the file has changed than really has. You can interact with files in the ubiquity container directly, working with them just as you would a file in your 'normal' document sandbox. This is the model prescribed in all of the iCloud documentation, sparse as it may be.

您是对的,您需要能够处理用户从iCloud迁移过来的情况.有一些方法可以将文件移出普遍存在的容器,并且某些较新的iOS 6 API可以更轻松地检测用户是否启用了iCloud,尽管这仍然是我们可以使用更多API的领域.

You're right that you need to be able to handle the situation where a user migrates away from iCloud. There are methods to move a file out of the ubiquity container and some of the newer iOS 6 API makes it easier to detect if the user has iCloud enabled, though this is still an area where we could use more API.

这篇关于如何通过NSFileManager正确管理iCloud文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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