Accessing "iCloud Drive" folder in Files on iPhone from App written in Swift

I am trying to read and write a text file from an App written in Swift in XCode directly to the "iCloud Drive" folder in Files on the iPhone.

The app worked readlly reading and writing to the Documents folder in the App container, and then readily to the "On My iPhone" folder in Files after adding 2 lines to the plist that I found in a search online.

But I have been unable to get to the iCloud Drive folder.

I found an item called "Enabling Document Storage in iCloud Drive" in "iCloud Design Guide" with additional plist entries that states "These settings allow iCloud Drive to provide public access to the files stored in your app’s container":

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

I think I changed the MyApp items appropriately.

I have enabled iCloud in my App and the XCode General, and Signing entries.

But this does not work. There are no error messages and no "Steps" shown in the "Capabilities" entry in Xcode.

A little help? :-)

Answered by DTS Engineer in 821528022

I believe your question is answered in the following sample code Readme section:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I believe your question is answered in the following sample code Readme section:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank you. I had not seen the reference to build number. However I still need help with moidifying the "iCloud.com.example.apple-samplecode.SimpleiCloudDocument" line.

What exactly do I substitute for "example", "apple-sample code", and "SimpleiCloudDocument"? Thanks!

You will need to replace the "iCloud.com.example.apple-samplecode.SimpleiCloudDocument" with your own iCloud container. See step 3 in the Configure the sample code project section for how to configure your own iCloud container.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Accessing "iCloud Drive" folder in Files on iPhone from App written in Swift
 
 
Q