In this blog post, I will show how you can ensure the user can access your app's files in the Documents directory through other services like Spotlight or the Files app.
Store local files in the
Documents directory of your app's container when you intend to make those files user-visible.
try? "Hello, world!".write(to: URL.documentsDirectory.appending(path: "Demo.txt"), atomically: true, encoding: .utf8)
Per default, files in your app's
Documents directory will not be accessible in the iPhone's Files app.
Your app needs to support "Open in Place" and indicates that file sharing is enabled, both configured in your
Info.plist file by adding the following property list keys:
<key>UIFileSharingEnabled</key> <true/> <key>LSSupportsOpeningDocumentsInPlace</key> <true/>
Files app can show them now in the "On My iPhone" or "On My iPad" location.
People can also find their files in Spotlight and on iPad, drag and drop them to other apps.
A summary on YouTube is available: