Saving file into system

Discussion in 'iOS Development' started by Just_For_Now, Aug 23, 2010.

  1. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    Im trying to save plist and a text file to the system for use later on in the iPhone file system. Though cant figure out why my code isnt working. Here is what im using.
    [OBJC]
    #define TEXTPATH @"/private/var/mobile/"

    - (void)viewDidLoad {
    NSString *testTEXT = [[NSBundle mainBundle] pathForResource

    Please Register or Log in to view images

    "Test" ofType

    Please Register or Log in to view images

    "txt"];
    [testTEXT writeToFile:TEXTPATH atomically:YES encoding:NSUTF8StringEncoding error:NULL];
    }
    [/OBJC]

    Am i doing this wrong?
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Assuming that the logic of fetching the path of a file and writing it [the path] to another file is correct, and assuming that a file Test.txt exists in the correct place, the problem is caused by you attempting to write to a directory, which you cannot do.
  3. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    You are going to write YourApplication/Resources/Test.txt into /private/var/mobile/. The application is under sandbox.
  4. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    Well I loaded the text file into a textview and it read it fine. So it recognizes the file. Its just placing the file into the system which is troubling.

    @NolesFans What do you mean? Should i ssh the app in to not use sandbox or what?
    ------------------double post merged------------------
    So i cant? What if i create a new directory?
  5. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    You are attempting to write to /var/mobile which physically is a directory. On Unix-like systems, a directory is a file to which you cannot write. You can create/write to a file in a directory.
  6. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    Ok so how about i create a txt file from the app and write into a directory?
  7. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    So many ways to do this..

    Code:
    NSMutableString * path = [[NSMutableString alloc] initWithString:@"/private/var/mobile/"];
    [path appendFormat:@"test.txt"];
    [testTEXT writeToFile:path atomically:YES];
    [path release];
    
  8. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    Ok, that was simple. Now how to unSandbox my application to gain access of the iPhone file system? There's a tutorial here, but I can't quite understand how this is done.
  9. Freerunnering

    Freerunnering Member

    Joined:
    Sep 1, 2009
    Messages:
    296
    Likes Received:
    0
    Device:
    4G iPod touch
    Try running your app from /applications instead of where xcode installs it.
  10. Just_For_Now

    Just_For_Now Active Member

    Joined:
    Mar 21, 2009
    Messages:
    1,898
    Likes Received:
    1
    Device:
    4G iPod touch
    SSHing the app in /Applications makes my app crash. When I Build & Go in Xcode it works fine.
    Any ideas?

Share This Page