File system access

Discussion in 'iPhone/iPad Programming' started by pinsrw, Oct 1, 2010.

  1. macrumors regular

    Joined:
    May 30, 2010
    #1
    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.
     
  2. macrumors 6502a

    (marc)

    Joined:
    Sep 15, 2010
    Location:
    the woods
    #2
    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.
     
  3. thread starter macrumors regular

    Joined:
    May 30, 2010
    #3
    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...
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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.
     
  5. macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #5
    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
     
  6. thread starter macrumors regular

    Joined:
    May 30, 2010
    #6
    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.
     

Share This Page