Reputation: 7440
I am trying to creating a file on my MacOS FS from my IPhone app by means of this code
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
path = [path stringByAppendingPathComponent: @"log.txt"];
NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:path];
if(output == nil) {
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
output = [NSFileHandle fileHandleForWritingAtPath:path];
} else {
[output seekToEndOfFile];
}
I guess the code is OK as it works when executed by the Simulator. However I can't actually see where the file is created when executed from the IPhone. If I print the path I get
/var/mobile/Applications/XXX-XXXX-XXX-XXX/Documents/log.txt
Upvotes: 0
Views: 415
Reputation: 906
On the simulator, you should find them under: /Users/loginname/Library/Application Support/iPhone Simulator/5.1/Applications/594931F3-B9EF-4B2C-833D-76C2DCC61C6B/Documents. You can go to this location from Finder by choosing the Go menu item, holding down the Option key, then choosing Library.
NOTE: Fill in your own loginname and device ID in the path above.
If you are on the device, you can copy the file over to your Mac using XCode, using the organizer (choose Window | Organizer). Highlight the App (after it has been executed, of course) and there is an option to copy the file over. You don't have direct access to the device file system.
You can also use NSLog() which just sends the debug info to the output window in XCode.
EDIT: Added detail on how to show Library folder.
Upvotes: 2