可以从 iCloud 驱动器下载文件吗?

It is possible to download files from iCloud drive?

假设我们有一个名为 "myImage.png" 的图像文件,我通过网站 www.icloud.com.

在我的 iCloud 驱动器上添加了这个文件

为此,我测试了很多代码,例如 this, this,最后尝试使用命令 startDownloadingUbiquitousItemAtURL,其中 none 有效(我可以下载仅当存在于以下路径中的文件:)

/Users/mynamemac/Library/Developer/CoreSimulator/Devices/07BAC437-D32A-44BB-BC25-5683222B7516/data/Library/Mobile%20Documents/

知道我想将文件存储在我的 iCloud Drive 中并保存在我的目录中,如何下载此文件并保存到我的设备上?

通常,您应该先打开 iCloud 驱动器,将其添加到您的 info.plist 文件中。

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.com.example.MyApp</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
        <string>Any</string>
        <key>NSUbiquitousContainerName</key>
        <string>MyApp</string>
    </dict>
</dict>

然后,您应该在项目的 Capabilites 选项卡下打开 iCloudXCode 将自动为您添加权利。
您可以使用此代码来检查您是否可以访问 iCloud。
[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
您应该参考 iCloud Design Guide 了解更多信息。