阅读背景:

为iCloud改造我的应用

来源:互联网 

I have been puzzling about retrofitting my app for iCloud for a few days and hope someone can help. After getting past code signing issues I am not sure I understand the model for incorporating iCloud. I'll tell you the problem I'm trying to solve first since I'm a big believer in telling people what I'm trying to do before having them try to fix the way I'm doing it :-)

几天来,我一直在为iCloud改造我的应用程序而苦苦思索,希望有人能帮上忙。在解决了代码签名问题之后,我不确定我是否理解整合iCloud的模型。我会先告诉你我想要解决的问题,因为我相信在别人试图纠正我的做法之前,我应该先告诉他们我想做什么。

My app workflow

我的应用程序工作流程

  1. User browses the store which lists a series of training plans they can download
  2. 用户浏览商店,列出了他们可以下载的一系列培训计划。
  3. User picks a plan and downloads it
  4. 用户选择一个计划并下载它
  5. I pull the training plan from our webserver customized to their needs
  6. 我从我们的webserver中提取培训计划,根据他们的需求定制
  7. I add the filename for the training plan they downloaded to a plist of plans they own
  8. 我将他们下载的培训计划的文件名添加到他们所拥有的培训计划的plist中
  9. User opens the training plan and sees the day-to-day schedule
  10. 用户打开培训计划并查看日常计划

I want the user to be able to do this on their iPhone and then open their iPad and see the exact same training plans synced over there.

我希望用户能够在他们的iPhone上这样做,然后打开他们的iPad,看到完全相同的培训计划在那里同步。

My problem I currently save the files to the Documents directory and that works just fine. How do I retrofit this to work with iCloud such that folks without iCloud enabled can continue to use the app but those who do get the added benefit?

我的问题是,目前我将文件保存到Documents目录中,这很好。我如何改造它,使之与iCloud协同工作,使没有iCloud的人们可以继续使用这个应用,而那些得到额外好处的人呢?

My understanding I'm confused as to whether I still need to save to Documents folder and then save a copy to the iCloud folder OR whether I just write to the iCloud folder from now on.

我的理解是,我是否还需要保存到文档文件夹,然后保存到iCloud文件夹中,或者从现在开始写到iCloud文件夹。

If it's the former I believe I just write a copy the Documents folder files to the iCloud area too to push it up but how do I detect a new file in the iCloud folder and copy it back to my Documents folder?

如果是前者,我认为我只是将文件文件夹文件复制到iCloud区域,以推动它,但我如何在iCloud文件夹中检测到一个新文件并将其复制到我的文档文件夹?

If it's the latter the files should just exist right?

如果是后者文件就应该存在?

I'm hoping it's the latter and that still supports devices without iCloud turned on...

我希望是后者,而且还能支持没有iCloud的设备……

Thanks for any help clarifying.

谢谢您的帮助。

Adam

亚当

2 个解决方案

#1


3  

The iCloud API is pretty well documented and there is a specific chapter that deals with what you are after:

iCloud API已经被很好地记录下来了,有一个特定的章节来描述你在追求什么:

Managing the Life Cycle of a Document

管理文档的生命周期

A document goes through a typical life cycle. A document-based application is responsible for managing its progress through that cycle. As you can see from the following list, most of these life-cycle events are initiated by the user:

文档经历一个典型的生命周期。基于文档的应用程序负责管理整个周期的进度。从以下列表中可以看出,这些生命周期事件大部分是由用户发起的:

  1. The user first creates a document.
  2. 用户首先创建一个文档。
  3. The user opens an existing document and the application displays it in the document’s view or views.
  4. 用户打开一个现有的文档,应用程序将其显示在文档的视图或视图中。
  5. The user edits the document. A user may ask to put a document in iCloud storage or may request the removal of a document from iCloud storage.
  6. 用户编辑文档。用户可以要求将文件放入iCloud存储中,也可以要求从iCloud存储中删除文件。
  7. During editing, saving, or other actions, errors or conflicts can happen; the application should learn about these errors and conflicts and either attempt to handle them or inform the user.
  8. 在编辑、保存或其他操作期间,可能发生错误或冲突;应用程序应该了解这些错误和冲突,并尝试处理它们或通知用户。
  9. The user closes a selected document. The user deletes an existing document. The following sections discuss the procedures a document-based application must complete for these life-cycle operations.
  10. 用户关闭选定的文档。用户删除现有文档。下面几节讨论基于文档的应用程序必须为这些生命周期操作完成的过程。

In essence, you application is responsible for working out whether iCloud is available for a particular user and then confirm that the user wants to store their data in the cloud. Based on that selection you will need to work out how to move their existing data from the documents directory to a cloud URL.

本质上,您的应用程序负责计算特定用户是否可以使用iCloud,然后确认用户希望将其数据存储在云中。基于这个选择,您需要找出如何将现有数据从documents目录移动到cloud URL。

On other devices that are setup to use iCloud storage, you have the option to discover documents available via a metadata query.

在使用iCloud存储的其他设备上,您可以通过元数据查询发现可用的文档。

https://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/DocumentBasedAppPGiOS/ManageDocumentLifeCycle/ManageDocumentLifeCycle.html#//apple_ref/doc/uid/TP40011149-CH4-SW1

https://developer.apple.com/library/ios/文档/ DataManagement /概念/ DocumentBasedAppPGiOS / ManageDocumentLifeCycle ManageDocumentLifeCycle.html # / / apple_ref / doc / uid / TP40011149-CH4-SW1

#2


1  

If you are looking for a very easy sample which implements iCloud, have a look at this:

如果您正在寻找一个实现iCloud的非常简单的示例,请查看以下内容:

iCloud basics and code sample

iCloud基础服务和代码示例

This gives you a concrete example of how to implement some of the stages Rog has cited in his post above. Hope this helps.

这给你一个具体的例子,如何实现Rog在他的文章中提到的一些阶段。希望这个有帮助。


分享到: