开发者

NSCachesDirectory not a directory in my file system

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 开发者_JAVA技巧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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜