PDA

View Full Version : File system access




pinsrw
Oct 1, 2010, 09:07 AM
My iPad app needs to store its data in some files.
On the simulator, my program can read and write its data files just fine.
It stores its data, then I tell it to exit and later when I run the app, it reads that
data in just fine. I just tried running the app on an iPad however and
it appears that file writing is not happening. Is there some sort of
limitation that's imposed on ad hoc apps during testing that doesn't
appear in real apps? My app has already been accepted and is being sold
so I assume it's just my iPad that has got this problem. Note, I did not
update iOS before running the app on the iPad.
Thanks.



(marc)
Oct 1, 2010, 12:14 PM
You can do things in the Simulator that you can't on the device. Permissions differ from the Simulator to the device. You can use NSFileManager to find out what the error is and then post back here.

pinsrw
Oct 1, 2010, 01:31 PM
You can do things in the Simulator that you can't on the device. Permissions differ from the Simulator to the device. You can use NSFileManager to find out what the error is and then post back here.

I fixed it. I was creating a file in $HOME. Turns out $HOME is not writable but $HOME/Documents is. Now, if I only knew why $HOME doesn't point into /Users...

dejo
Oct 1, 2010, 01:59 PM
I fixed it. I was creating a file in $HOME. Turns out $HOME is not writable but $HOME/Documents is. Now, if I only knew why $HOME doesn't point into /Users...
You shouldn't be using $HOME on the device. You should be retrieving the Documents folder via NSSearchPathForDirectoriesInDomains(NSDocumentDirectory...

As for /Users, there's no such thing on a device.

ulbador
Oct 1, 2010, 02:36 PM
Does $HOME actually even resolve to anything in code?

That is a special environment variable that gets set when you log in via something like bash or csh, and wouldn't actually exist anywhere else but on a unix-like terminal..

I'm guessing it probably wasn't resolving to anything and you were just opening /Documents... who knows though

pinsrw
Oct 2, 2010, 06:20 PM
Does $HOME actually even resolve to anything in code?

Oh yes, definitely... on the iPad.
Calling getenv("HOME") gives the path to the Applications directory for the app.
I'd guess one ought not rely on it though.