iCloud Documents + UIDocumentBrowserViewController

Our app is a document-based app that uses UIDocumentBrowserViewController. We are facing an issue when the user is creating a new document on iOS/iPadOS when in the “Recents” tab (as opposed to the “Browse” tab). Specifically, the document is saved to a hidden ubiquity container. As a result, the user cannot find the file in the document browser. It also does not appear in “Recents”. The expected behaviour would be a folder with our app's icon on it on the user’s iCloud Drive, which contains the files the user creates when in the “Recents” tab.

This issue started to happen when we introduced a new feature that uses iCloud Documents with its own ubiquity container. I'm not sure how UIDocumentBrowserViewController handled saving documents to a default location on iCloud Drive before we had the iCloud Documents entitlement enabled. All I know is that there were no issues.

How to recreate the issue:

Create a document-based app with UIDocumentBrowserViewController. Run the app and create a document while in the recents tab with iCloud enabled. The document will be stored to a folder on iCloud.

Now, enable iCloud Documents and specify a ubiquity container. Then, try to create documents in the Recents tab. The location in which the documents are created cannot be navigated to.

"The document will be stored to a folder on iCloud."

If you don't do anything special, the document will by default be in the Documents folder in your app's sandbox, which is your app's folder under the "On My iPhone" location.

Now, enable iCloud Documents and specify a ubiquity container. Then, try to create documents in the Recents tab. The location in which the documents are created cannot be navigated to.

Did you try to expose your ubiquity container to iCloud Drive yet? If not, please follow the Publish an iCloud Container to iCloud Drive section of the Synchronizing Documents in the iCloud Environment sample to do so. After that, your ubiquity container should show up as a folder under iCloud Drive, and you might be able to find the file from there.

Note that the steps listed in the section needs to be strictly followed, especially step 2 – If you don't increase the bundle version, the system may not refresh the metadata immediately, and so the folder may not show up.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Hi. Thank you for your reply! To be clear, none of these changes will affect the current version of the app on the App Store, correct? I can add and remove ubiquity containers, change entitlements, etc.

Only if I were to proceed to publish a new version with the changes, would these changes take affect?

Yeah, that's correct.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

That worked! My ubiquity container is now showing in iCloud Drive.

I have a follow up question concerning my setup of com.apple.developer.icloud-container-identifiers and com.apple.developer.ubiquity-container-identifiers:

Here is my setup:

<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.com.mycompany.documents</string>
<string>iCloud.icloud.com.mycompany.myapp</string>
</array>

and

<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.com.mycompany.documents</string>
<string>iCloud.icloud.com.mycompany.myapp</string>
</array>

Yes, “iCloud.icloud…” is an annoying typo. iCloud.com.mycompany.documents is used for iCloud Documents and iCloud.icloud.com.mycompany.myapp is used for CoreData + iCloud.

The order of com.apple.developer.icloud-container-identifiers seems to matter to UIDocumentBrowserViewController, as it saves documents created in the Recents tab to the first container of this list.

I now read here that “One of these strings must be the bundle identifier for your app” for com.apple.developer.ubiquity-container-identifiers. Is this still the case? None of my strings listed in either list corresponds to my bundle identifier. Note that during my testing everything seems to work fine with the above setup. Can I safely continue with the above setup?

"I now read here that “One of these strings must be the bundle identifier for your app” for com.apple.developer.ubiquity-container-identifiers. Is this still the case?"

No, that is not the case anymore.

"None of my strings listed in either list corresponds to my bundle identifier. Note that during my testing everything seems to work fine with the above setup. Can I safely continue with the above setup?"

I think so, but please make sure to test the new version of your app with TestFlight before releasing it to your customers. I don't see anything wrong in the configuration you described, but It’s hard for me to do an end-to-end test because I can’t publish apps on the store.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

iCloud Documents + UIDocumentBrowserViewController
 
 
Q