I could really use some help with file开发者_运维百科s (images) download/save application process.
I need some methods to:
- Create hidden (accessable from my app only) directory
- Save files (images + maybe 1 XML file) to such directory
- List all of these directories and later list all files the selected directory contains
I know how to do it on Android, however on iPhone it seems a bit unclear.
Use this code to obtain your application's Documents directory path. This directory is only accessible from your application.
- (NSString *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
return basePath;
}
To save and load files from there, you can use any of a wide range of methods, from C functions (fopen
and the like) to Cocoa convenience methods like NSString's
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error
精彩评论