根据苹果的iCloud文档:
每个拥有Apple ID的用户都会收到一个免费的iCloud帐户,但有些用户可能会选择不为给定设备启用iCloud。 在尝试使用任何其他iCloud接口之前,必须调用URLForUbiquityContainerIdentifier:方法以确定是否启用了iCloud。 启用iCloud(并且指定的容器目录可用)时,此方法返回有效URL,或禁用iCloud时返回nil。
如果URLForUbiquityContainerIdentifier:返回nil,那么我认为你必须保存到用户的文档目录。 如果用户以后启用iCloud,您应该怎么做? 文档只告诉你在一切进行计划时该怎么做,但是没有提到处理其他任何事情的最佳实践......如果iCloud被禁用,icloud文档的本地副本是否会被删除,或者删除了它的权限从沙箱?
According to apple's iCloud docs:
Every user with an Apple ID receives a free iCloud account but some users might choose not to enable iCloud for a given device. Before you try to use any other iCloud interfaces, you must call the URLForUbiquityContainerIdentifier: method to determine if iCloud is enabled. This method returns a valid URL when iCloud is enabled (and the specified container directory is available) or nil when iCloud is disabled.
If URLForUbiquityContainerIdentifier: returns nil, then I presume you have to save to the user's documents directory. What are you supposed to do if the user enabled iCloud at a later date? The docs only tell you what to do when everything goes to plan, but make no mention of best practices for handling anything else... What if iCloud gets disabled, will the local copy of the icloud document get deleted, or have it's permissions removed from the sandbox?
最满意答案
您应该保存iCloud启用状态(即,您是否能够从URLForUbiquityContainerIdentifier:获取nonnil结果URLForUbiquityContainerIdentifier: ,注册情况变化的通知等。如果您检测到状态已从关闭更改为开启,则解决方案是简单; call setUbiquitous:itemAtURL:destinationURL:error:将文件从你的世界复制到无处不在的世界(毕竟它只是一个文件夹)。
这种情况在文档中有很好的介绍:
http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html
不幸的是,如果您检测到相反的情况(用户已关闭iCloud),文件将丢失并且您无法检索它,因为,假设, URLForUbiquityContainerIdentifier:现在返回nil。 但它仍处于云端。 我认为你可以提供让用户重新打开iCloud的界面,以及让用户请求将文件移回nonubiquity世界的更多界面。
You should save the state of iCloud enablement (i.e. were you able to get a nonnil result from URLForUbiquityContainerIdentifier:), register for notifications of changes to the situation, etc. If you detect that the state has changed from off to on, the solution is simple; call setUbiquitous:itemAtURL:destinationURL:error: to copy the file from your world into the ubiquity world (it's just a folder, after all).
This situation is pretty well covered in the docs:
http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html
Unfortunately, if you detect the opposite (the user has turned off iCloud), the file is lost and you can't retrieve it, because, ex hypothesi, URLForUbiquityContainerIdentifier: is now returning nil. But it is still in the cloud. I presume you could provide interface for asking the user to turn iCloud back on, and more interface for letting the user request that the file be moved back into the nonubiquity world.
更多推荐
发布评论