简体   繁体   English

如何为iOS应用正确启用iCloud文档同步?

[英]How do I properly enable iCloud document sync for iOS app?

In my cordova iOS app, users can back up their data to a file which is saved in the Documents folder within the app's container, which then should be synced to iCloud. 在我的cordova iOS应用程序中,用户可以将其数据备份到文件中,该文件保存在应用程序容器内的Documents文件夹中,然后应同步到iCloud。 However, though the file is saved it is never synced to iCloud, so clearly I must be missing something. 但是,尽管文件已保存,但从未同步到iCloud,因此很明显我必须丢失一些内容。 These are the steps I have taken: 这些是我已采取的步骤:

  • iCloud container registered on developer.apple.com and iCloud Documents capability enabled in xcode: 在developer.apple.com上注册的iCloud容器和在xcode中启用的iCloud文档功能:

iCloud容器

  • NSUbiquitousContainers dictionary added to Info.plist: NSUbiquitousContainers词典已添加到Info.plist:

iCloud信息

  • Archive build created and uploaded to App Store, build released to testers via Test Flight (Note: app has already gone through review process and been released to App Store). 创建存档版本并将其上传到App Store,并通过Test Flight将版本发布给测试人员(注意:应用程序已经通过审核并已发布到App Store)。
  • Note, Cordova config.xml does not contain BackupWebStorage setting so cloud backup should be enabled (not sure exactly whether this affects document sync). 注意,科尔多瓦config.xml中包含BackupWebStorage设置这样的云备份应该启用(不知道这究竟是否会影响文件同步)。
  • User saves backup file, which is saved to app's Documents folder (Note: the app uses the cordova-plugin-file plugin to save the file to the location denoted by the plugin variable cordova.file.documentsDirectory ): 用户保存备份文件,该文件保存到应用程序的Documents文件夹中(注意:该应用程序使用cordova-plugin-file插件将文件保存到插件变量cordova.file.documentsDirectory指示的位置):

IEXPLORER

At this point I would have expected to see xBrowserSync appear in Storage & iCloud usage settings, but I do not: 在这一点上,我本来希望看到xBrowserSync出现在“存储和iCloud使用情况”设置中,但我没有:

存储和iCloud使用

And neither do I see an xBrowserSync folder appear in the iCloud Drive app: 而且在iCloud Drive应用程序中也看不到xBrowserSync文件夹:

iCloud云端硬碟

And of course I never see the files synced to my Mac or on icloud.com. 当然,我从没看到文件同步到Mac或icloud.com。

Clearly I'm missing something but I can't see what. 显然我缺少了一些东西,但看不到。 I've read many SO posts regarding getting this working and I find Apple's documentation unclear and confusing so I'm kind of stuck at this point. 我已经阅读了许多有关如何使它工作的SO帖子,并且我发现Apple的文档不清楚且令人困惑,因此我有点被困在这一点上。 Could someone please point me in the right direction? 有人能指出我正确的方向吗?

After some further reading I believe I know what's missing here. 经过进一步的阅读,我相信我知道这里缺少什么。 I hadn't realised you need to explicitly tell iOS to upload a file to iCloud Document Storage , which is what will allow files to appear in iCloud Drive on the user's devices. 我还没有意识到您需要明确地告诉iOS将文件上传到iCloud文档存储 ,这将允许文件出现在用户设备上的iCloud Drive中。

So, I need to write some (iOS) code that utilise the FileManager class to: 因此,我需要编写一些使用FileManager类的(iOS)代码以:

  1. Call the url(forUbiquityContainerIdentifier:) method in order to get the location of the local iCloud container and initialise it (at which point the app will appear in Storage & iCloud usage settings) 调用url(forUbiquityContainerIdentifier:)方法以获取本地iCloud容器的位置并对其进行初始化(这时该应用程序将出现在“存储和iCloud使用情况”设置中)
  2. Tell iOS to upload the file to iCloud by calling setUbiquitous(_:itemAt:destinationURL:) 通过调用setUbiquitous(_:itemAt:destinationURL:)告诉iOS将文件上传到iCloud。

I'm building a very basic Cordova plugin to do this. 我正在构建一个非常基本的Cordova插件来执行此操作。 I'll update this answer with a link when I'm finished. 完成后,我将通过链接更新此答案。

Edit: 编辑:

The cordova plugin I developed is called cordova-plugin-icloud-document-storage . 我开发的cordova插件称为cordova-plugin-icloud-document-storage It currently only implements uploading documents to iCloud (ie setUbiquitous ), it doesn't implement the other iCloud functionality of the FileManager class (such as managing cloud updates or version conflicts). 它当前仅实现将文档上传到iCloud(即setUbiquitous ),而没有实现FileManager类的其他iCloud功能(例如管理云更新或版本冲突)。 If anyone would like to develop this functionality please do submit a pull request. 如果有人想开发此功能,请提交拉取请求。

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

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