2
votes

Suppose we have an image file called "myImage.png" and I added this file on my iCloud drive through the website www.icloud.com.

For this I test many codes like this, this, and finally try to use the command startDownloadingUbiquitousItemAtURL and none of them worked (I can download the files only if exist inside this path below:)

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

Knowing that I would like to take the file storage in my iCloud Drive and save in my directory, how I can download this file and save on my device?

1
Is it possible to share link via iCloud using any iCloud apis?Govind

1 Answers

2
votes

Generally, you should turn on iCloud drive first, add this to your info.plist file.

<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>

Then, you should turn on iCloud under the Capabilites tab of your project. XCode will add the entitlements for you automatically.
You can use this code to check whether you have access to iCloud or not.
[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
You should refer to iCloud Design Guide for more information.