Documentation is very limited online, but apparently you need both Info.plist flags
UIFileSharingEnabled
and LSSupportsOpeningDocumentsInPlace
to get the Documents directory
visible in the Files app in the "On My iPhone" section.
Last active
August 31, 2023 17:27
-
-
Save babldev/1b86a91907611ec25675e42d3b3709bc to your computer and use it in GitHub Desktop.
Make iOS app files saved to Documents directory visible in the Files app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>UIFileSharingEnabled</key> | |
<true/> | |
<key>LSSupportsOpeningDocumentsInPlace</key> | |
<true/> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func writeTextToFile() { | |
// The text you want to write | |
let text = "Hello, world!" | |
// Getting the URL of the Documents directory | |
if let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { | |
// Creating the full URL by appending the text file name | |
let fileURL = documentsDirectory.appendingPathComponent("MyTextFile.txt") | |
do { | |
// Writing the text to the file | |
try text.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8) | |
print("Successfully wrote text to file at \(fileURL)") | |
} catch { | |
// Handle the error | |
print("An error occurred: \(error)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment