Question

I have read a lot about accessing files in an iPhone app, but I cannot figure out how to get them there in the first place. I have many sound files that are important to my app, and many more that can be purchased using IAP. I know that these files should go in my /Library/Application Support/ directory, however I cannot figure out how to get them there. How do I do this? I am sure that there is something incredibly obvious that I'm missing, but I can't figure it out. Also, in my app there is a UITableView that keeps track of these files. What is the best way to keep that table's datasource up-to-date as the user purchases new sounds? I would assume keeping an array in my model would be best, but I'm not sure how to read and write the contents of an array to disk. Any help is appreciated.

Was it helpful?

Solution

You can use this code to create your folder and then save your files there.

NSArray *filePaths =    NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask,YES); 
NSString *path=[filePaths objectAtIndex: 0];
NSString *tempPath=[[NSString alloc]initWithFormat:@"%@/%@",path,@"TempFolder"];

BOOL bDir;
NSError *error;
if([[NSFileManager defaultManager] fileExistsAtPath:tempPath isDirectory:&bDir]==FALSE){
    [[NSFileManager defaultManager] createDirectoryAtPath:tempPath withIntermediateDirectories:YES attributes:nil error:&error];
}

Then use this code to save your files in your folder

NSArray *filePaths =    NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask,YES);
NSString *pathAndName=[[NSString alloc] initWithFormat:@"%@/TempFolder/%@",
                       [filePaths objectAtIndex: 0],
                       fileName];
NSData * data = //Load your file here
[data writeToFile:pathAndName atomically:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top