Saving to the documents folder with iOS

Hi all, this is my first attempt at mixing Xojo and iOS.

I am attempting to simply save a text file to the documents folder of an iPhone. However when I run the app on my Mac and run the following code, nothing appears in the documents folder.

Dim file As FolderItem = SpecialFolder.Documents.Child("MyFile.txt") If file <> Nil Then me.Caption = "found" Dim output As TextOutputStream output = TextOutputStream.Create(file, TextEncoding.UTF8) output.WriteLine("a") output.WriteLine("b") output.WriteLine("c") output.Close End If

The file is definitely being saved because I am also able to read it with the following code.

Dim f As FolderItem = SpecialFolder.Documents.Child("MyFile.txt")
If f.Exists Then
  Dim input As TextInputStream
  input = TextInputStream.Open(f, TextEncoding.UTF8)
  me.caption = input.ReadAll
  input.Close
End If

Is this because I am simulating the app with Xojo rather than running an actual built version on an iOS device? Or am I saving the file in some way that it is invisible to the user.
The simulator device I have selected is the iPone 11 (iOS 13.3).

Any help would be greatly appreciated.

the “documents” folder for the iOS simulator IS NOT the same as the macOS documents folder… it is in a special directory allocated to the iOS simulator for what ever device/app you are simulating… This means if you simualate an iPhone8 the files will be one place, if you simulate an iPad they will be somewhere else… but at NO TIME will they every be in any file belonging to the macOS operating system (ie. Applications, Documents, etc)

What do mean the file is not in the Documents folder? Where are you looking?

The iOS Simulator saves stuff in weird places. Look at your file.Path variable in the debugger to see where your iOS app’s Documents folder is on the Mac.

for example… here is the path to the /Documents for a Swift program in the Simulator (Xojo should be almost identical)

/Users/davidS/Library/Developer/CoreSimulator/Devices/0C5EF0D3-E5A6-4EAE-A0F1-7DEBA9E4EE82/data/Containers/Data/Application/F69E7CC7-9535-497B-95A7-CEFE8DB00C95/Documents/

NOTE : those UUID will vary depending on what you are simulating

Thanks Dave, Paul

My mistake, I assumed that as part of the simulation I would be able to open the documents app on the simulated iOS device and see the files I had saved.

You can… just need to determine WHERE that folder is stored… IT IS on your mac… just need to have your app dump the path for you (as I did above)… just remember… if you change simulated devices, that path WILL BE different each time