i met a problem with iphone simulator application directory, when i run the application everytime, the name of application directory was changed each of time,can anyone tell me how to keep a static application directory ?
views:
1360answers:
4If you simply relaunch the app from within the simulator springboard it will keep using the same directory. If you rebuild the app in Xcode it will move, and there is no way to prevent that. Xcode should migrate any data you have from the old directory to the new directory when it installs the new build.
thanks for you reply,but if i need to use the file in that application directory is it possible i can save it to a fix directory before i end up my application, what i add in my program?
i'm going to take a guess here and say..
you don't need a static directory.
I think what you need is to get the 'base directory' programatically.
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *path = [docsDirectory stringByAppendingPathComponent:@"fileName.txt"];
you should be saving your user files there (or somewhere similar)
or alternatively something like
NSBundle* bundle = [NSBundle mainBundle]; NSString* path = [bundle executablePath] //or NSString* path = [bundle resourcePath];
and then append your own paths onto that.
hope that helps.
NEW INFO:
If you are saving information, (a log, stats etc..) you can retrieve the files saved in the NSDocumentDirectory above using the Xcode organiser.
- select your device
- got the summary tab
- find you application in 'Applications' section.
- expand the entry and it should have an 'Applcation data' entry.
- press the down arrow on the right to save your files.
I guess the problem is that XCode sometimes "loses" files.
So I lost all my preferences just now, and unable to get them back because XCode, once they are lost, can't recover them.
Here is what I did to resolve:
- Open the console, note the directory it's using for the new launch, in my case that was /Users/nik/Library/Application Support/iPhone Simulator/User/Applications/D713AFE6-D6B3-4D1E-A1B9-28FD679FD124/Documents/
- Quit the app
- Go to /Users/nik/Library/Application Support/iPhone Simulator/User/Applications and look for a launch that still has the preferences files in /Documents
- Copy the preferences files to the last launch location above
- Launch again - now it all worked. XCode created yet another temporary launch directory, but moved the files from the "last" launch over.
I am now also saving the preferences file in another location so next time this happens I have them handy.