Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-15-2010, 10:39 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 195
Son of a Beach is on a distinguished road
Default Where to Store Persistent Files in iOS 4?

Where should apps store persistent files (eg, CoreData persistent store files)?

Apple's doco has always said to use the 'Documents' directory, however in iOS 4 this directory is exposed to the user for read/write file sharing through iTunes for apps that enable it.

Apple's doco explicitly recommends against storing files directly in 'Library/Preferences'.

So where are our apps supposed to store our files if we want to enable the file sharing, but do not want users to clobber important persistent files?

Should we be creating additional directories under 'Library'? Eg, 'Library/Data', or 'Library/Application Support'?
Son of a Beach is offline   Reply With Quote
Old 06-15-2010, 10:43 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 195
Son of a Beach is on a distinguished road
Default

Hey, look at that... there already IS a 'Library/Application Support' directory!

Is this the place where my app should be storing its persistent files when I don't want the user having direct file sharing access to them?
Son of a Beach is offline   Reply With Quote
Old 06-16-2010, 12:10 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 195
Son of a Beach is on a distinguished road
Default

No answer yet?

I appears that the application support directory does not exist, but the constant and function exist to get a string for its path making it easy to create in a consistent location is a way that 'feels' like it's supported. Therefore the following works just fine for me in testing so far:

Code:
- (NSString *)applicationSupportDirectory
{
	NSString *dir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
	
	if ( ! [[NSFileManager defaultManager] fileExistsAtPath:dir] )
		[[NSFileManager defaultManager] createDirectoryAtPath:dir attributes:nil];
	
	return dir;
}
Does this "Library/Application Support" directory seem like a reasonable place to store persistent files that should not be directly accessible by the user while also using iOS 4 file sharing through iTunes (to the Documents directory).

Surely other people have got solutions to this? Anyone care to share?
Son of a Beach is offline   Reply With Quote
Old 06-16-2010, 01:59 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 160
Vortec4800 is on a distinguished road
Default

I'm not sure about the Application Support directory, but I've been creating a hidden directory in the Documents directory in iPad apps that have file sharing enabled. Remember you only need to worry about this if you're going to be using the sharing function and have it enabled - otherwise you can just use the Documents directory like normal.

Basically on launch I check to see if my hidden directory is there, if it isn't I make it and use that for any persistent files. Any directory that starts with a . will be hidden in iTunes (at least the Mac iTunes, not sure about Windows iTunes...) so I create something like Documents/.appfiles/MyApp.sqlite and that does the trick.
Vortec4800 is offline   Reply With Quote
Old 06-16-2010, 04:03 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 195
Son of a Beach is on a distinguished road
Default

Sounds reasonable, assuming it remains hidden in all situations including Windows. I guess there's a possibility (exceedingly remote) that the user could still clobber the files by copying in something with the same name.

It's really odd that Apple have done this in such a way that forces us to use kludge work arounds and don't appear to have any real solution documented.

One minute they're telling us to use the Documents directory for all our app data and the next thing they're exposing this directory to end users for file sharing without providing any recomended alternatives to app developers who are coming up with a variety of inconsistent and kludgy work arounds.
Son of a Beach is offline   Reply With Quote
Old 07-05-2010, 06:03 PM   #6 (permalink)
Registered Member
 
Northeast Canuck's Avatar
 
Join Date: Jan 2010
Location: North Vancouver
Posts: 44
Northeast Canuck is on a distinguished road
Default

Quote:
Originally Posted by Son of a Beach View Post
Sounds reasonable, assuming it remains hidden in all situations including Windows. I guess there's a possibility (exceedingly remote) that the user could still clobber the files by copying in something with the same name.

It's really odd that Apple have done this in such a way that forces us to use kludge work arounds and don't appear to have any real solution documented.

One minute they're telling us to use the Documents directory for all our app data and the next thing they're exposing this directory to end users for file sharing without providing any recomended alternatives to app developers who are coming up with a variety of inconsistent and kludgy work arounds.
I agree. I am working on an iPad app with file sharing enabled and I also persist data to a file which was previously located in the Documents directory. I am now using the '.folder' workaround but as was previously pointed out, this may not hide it on Windows which isn't satisfactory. Why couldn't Apple have just put an 'Files' folder inside of Documents which was made accessible to the public?
Northeast Canuck is offline   Reply With Quote
Old 03-04-2011, 11:23 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
redbergy is on a distinguished road
Default

I can confirm that .directories/files are hidden in the Windows version of iTunes as well as the Mac version. I do agree it is sort of a hack workaround, but it does work.
redbergy is offline   Reply With Quote
Old 12-03-2011, 11:03 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: VA
Posts: 50
zambono is on a distinguished road
Default

I have read that if you set your windows to view hidden files, that hidden directory is visible. better to save under a created directory in library
zambono is offline   Reply With Quote
Old 12-03-2011, 08:30 PM   #9 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Last time I looked, file sharing allowed reading from subdirectories, but not writing. Files sharing writes only allowed writing to the root of the Documents folder. Has this changed?
RLScott is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 324
9 members and 315 guests
Absentia, Domele, fiftysixty, givensur, heshiming, linkmx, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0