use*_*382 7 iphone caching objective-c ipad ios
我正试图在我的iPad应用程序的Caches文件夹中存储一些东西.
NSArray* cachePathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* cachePath = [cachePathArray lastObject];
Run Code Online (Sandbox Code Playgroud)
当我打印出返回的文件路径时,我得到:
/ Users/Gela/Library/Application Support/iPhone Simulator/5.0/Applications/3FF7EB1A-49A9-4B13-ADC4-DF0662BA724B/Library/Caches
但是,当我导航到硬盘驱动器上的该文件夹时,"缓存"不是文件夹,而是模糊的"文档"文件.
任何想法为什么它不是一个文件夹以及如何写入我的缓存?
Sri*_*aju 13
也许Simulator没有Cachesdir.你在设备上试试这个......
您可以Caches像这样访问目录.我使用这种方法获取文件数据......
- (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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20791 次 |
| 最近记录: |