iOS Question file.dirDocuments

sorex

Expert
Licensed User
Longtime User
Hello,

Is it normal that data written to file.dirDocuments is lost when you restart the app?

using code as below shows that the file always vanishes while it was there before.

with file.dirLibrary it seems to work fine tho.

B4X:
Log(File.ListFiles(File.DirDocuments))
File.WriteString(File.DirDocuments,"test.txt","test")
log("---")
Log(File.ListFiles(File.DirDocuments))

Application_Start
<B4IList: (
)>
---
<B4IList: (
"test.txt"
)>
 

sorex

Expert
Licensed User
Longtime User
that always returned false at a new run off the app.
not after writing the file firsT.

I've changed it to file.dirLibrary now wich always seems to work as expected.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Weird. I am using dirdocuments and it works fine. Are u using a real phone for testing?

Are u sure that u dont delete the file somewhere?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
yes, it was on a real iphone 4 device that it was tested.

the only file.delete line is commented.

strange is that my game settings file was also written to the documents location and that file is still visible there.
(altho I changed it to the library one a few versions ago)

testing it now as new project with only that code works on my "home" iphone 4 (the other one was at work)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
yes, it was on a real iphone 4 device that it was tested.

the only file.delete line is commented.

strange is that my game settings file was also written to the documents location and that file is still visible there.
(altho I changed it to the library one a few versions ago)

testing it now as new project with only that code works on my "home" iphone 4 (the other one was at work)

i would check if there is a file.delete command because it doesnot make any sense.

there is no reason that ios would delete any files that are stored in file.dirdocuments.
i would go over the code again.
 
Upvote 0

BjoernB

Member
Licensed User
there is no reason that ios would delete any files that are stored in file.dirdocuments.

same problem, a few years later. the program runs fine on several iphones and pads, but on the iphone 11 it won't save the app settings. so definetly no wrong placed file.delete
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
same problem, a few years later. the program runs fine on several iphones and pads, but on the iphone 11 it won't save the app settings. so definetly no wrong placed file.delete

i also have an iphone 11 and everything works fine on my iphone 11. if you can make a simple example where you can reproduce the error then upload and i will check it on my iphone 11.

btw are you using a real iphone or the simulator?
 
Upvote 0

BjoernB

Member
Licensed User
@ilan
real iphone 11,

switched from file.dirdocuments to file.dirlibrary, nothing changed. the iphone won't save any map data.

the code saving it is:

B4X:
Dim mp as Map

mp.Put("ip", "192.168.0.1")
mp.Put("port", "9999")
mp.Put("tnr", "1")
File.WriteMap(File.DirLibrary, "sma.map", mp)

don't know why, but the iphone 11 won't save this map.
even after rotating the Phone, all settings are gone.

reading it works that simple too:

B4X:
Dim mapdata as Map
if File.Exists(File.DirLibrary, "sma.map") then
  mapdata = File.ReadMap("File.DirLibrary, "sma.map")
End If

Maybe it's an old compiler version? i'm using 5.3, how about you?
 
Last edited:
Upvote 0
Top