6

I created a text file named Write.txt in the Documents folder in a Xamarin.iOS app. After that I was able to read its content to the console.

var documents = 
 Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(documents, "Write.txt");

File.WriteAllText(filename, "Write this text into a file");
var text = File.ReadAllText(filename);

Console.WriteLine(text);  // prints out correctly

The problem is, that I can't found this file on the iPhone simulator's Files app. There is no Documents folder anywhere, and I don't get any results if I search for the filename.

(Yes, I'm new in iOS, so sorry if the question is stupid :) )

kistelekig
  • 155
  • 6

2 Answers2

3

See Building Great Document-based Apps in iOS 11.

If you want to see it in the files app, you’ll want to set the following value in your Info.plist:

  • “Supports Document Browser” (UISupportsDocumentBrowser)

Or

  • “Application supports iTunes file sharing” (UIFileSharingEnabled); and
  • “Supports opening documents in place” (LSSupportsOpeningDocumentsInPlace)
Rob
  • 371,891
  • 67
  • 713
  • 902
  • That’s funny, because I tested both of these on iOS 13 before posting and it worked fine, showing the file in the app’s Documents folder within the Files app. – Rob Oct 19 '19 at 15:25
  • My document based app has UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace and it no longer appears in the Files app. I've seen other questions asking about the same thing. There must be some new further requirement but I haven't worked out what it is. – matt Oct 19 '19 at 15:26
  • It's a custom file type. Here is another example of the same issue https://stackoverflow.com/questions/58173265/ios-13-1-cannot-save-file-to-app-directory – matt Oct 19 '19 at 15:34
  • Here's another one; the OP claims this was fixed in an iOS update but that is not the case for me https://stackoverflow.com/questions/58125994/on-my-iphone-folders-how-to-create-a-folder-for-my-app-ios-13 – matt Oct 19 '19 at 15:57
  • I can't reproduce the problem. I created a custom file type (but none of the document-based app scaffolding, just a file with a custom extension) and a `txt` file, and when I look in the “On my iPhone” folder in Files, I see both of these on iOS 13.1 simulator and 13.1.3 device. (I don’t have any 13.0 device and see no such simulator. ☹️) If you can direct me to MCVE, I’m more than happy to take a look. – Rob Oct 19 '19 at 16:02
  • 2
    Whoa! In desperation I shut my phone down and restarted it, and not only my app but a whole bunch of apps showed up in the Files browser! I wonder how much that's behind other statements of the same issue. Sorry for the noise but this was a big surprise. – matt Oct 19 '19 at 16:05
  • Well, now I can't get iCloud to work with this app. Sigh. – matt Oct 19 '19 at 18:05
  • 2
    OK well I got _that_ to work by signing out of iCloud and back in again. It's like in iOS 13 nothing works until you smash it with a wrench. – matt Oct 19 '19 at 18:07
  • Confirmed that it is an iOS 13 issue. Rebooting sometimes help. Searching inside the Files app sometimes help. – WPK Jun 04 '20 at 23:22
2

I just run your code and it all works well on my side. The file you written to was successfully opened. I guess you might have some wrong step when opening the folder, let me show you how to do it:

1.I run your code and then print the file path(the filename in your code), on my side it is:

/Users/myName/Library/Developer/CoreSimulator/Devices/0F06FD18-4307-4102-8A30-5EB017A4BD26/data/Containers/Data/Application/20A0294B-36C5-484F-8BD1-B69B977BA378/Documents/Write.txt

2.Go to your mac --> select Finder --> Then open the Go menu --> Click Go to Folder

screenShot

3.Paste your path to the text box:

enter image description here

4.Click Go and you will see the file:

enter image description here

Some folders are hidden in your system so you can't see them when search for the filename. Feel free to ask me if you have any question.

Jack Hua
  • 14,231
  • 1
  • 5
  • 19