I'm trying to store something in my Caches folder on my iPad app.
NSArray* cachePathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* cachePath = [cachePathArray lastObject];
And when I print out the returned filepath, I get:
/Users/Gela/Library/Application Support/iPhone Simulator/5.0/Applications/3FF7EB1A-49A9-4B13-ADC4-DF0662BA724B/Library/Caches
However, when I navigate to that folder on my hard drive, "Caches" is not a folder but a vague "document" file.
Any ideas why it's not a folder and how I can write to my Cache?
Maybe Simulator
does not have Caches
dir. You try this on device...
You can access the Caches
directory like this. I use this method for getting file data...
- (NSString *)getFileData: (NSString *)fileDirPath
{
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *myPath = [myPathList objectAtIndex:0];
NSError *err = nil;
NSString *fData = @"";
myPath = [myPath stringByAppendingPathComponent:fileDirPath];
if([[NSFileManager defaultManager] fileExistsAtPath:myPath])
{
fData = [NSString stringWithContentsOfFile:myPath encoding:NSUTF8StringEncoding error:&err];
if(err) NSLog(@"getFileData() - ERROR: %@",[err localizedDescription]);
}
else
{
NSLog(@"getFileData() - ERROR: This file '%@' does not exist",myPath);
}
return fData;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With