SwiftU Document-based app error: "The document could not be opened"

I am building a document-based app with SwiftUI, but whenever I want to create a document in the app, the app shows an alert with the following title: "The document could not be opened"

I hit the same problem with Apple's sample project: https://developer.apple.com/documentation/swiftui/building_a_document-based_app_with_swiftui

The interesting part is that I only get this error message when I am creating a new file from the "Recents" tab, but when I am creating it from the "Browse" tab, then it works.

The beta testers from my app are also experiencing this issue, and they use multiple types of OS versions, and they have enough storage to create the files.

Replies

I'm guessing, but this sounds like a sandboxing issue. In order to create a new file, you need to have the com.apple.security.files.user-selected.read-write entitlement set to true. But a file chosen programmatically by a Recents menu isn't user-selected. If your Recents logic is storing a path to a file outside of your app's bundle or its own, sandboxed Documents folder, your program won't be able to open that file. If you store your recents as security-scoped bookmarks, it should work.

Hi! Can you file feedback, please, with the project (even if it is the sample project for Document-based apps) and the configuration that you use (e.g., Xcode, iOS versions, is it a simulator or a read device, etc)? Thanks in advance!