iOS8 document directory
路径检测中的问题:
使用以下代码将我的应用中下载的附件存储到documents directory
路径中。
//-- Store data to documents folder
NSString *resourceDocPath = [[NSString alloc] initWithString:[ [[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",fileName]];
[self.downloadedMutableData writeToFile:filePath atomically:YES];
使用以下代码检索文档表单路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
ios7
模拟器&设备ios8
设备中的正确路径也在模拟器中。ios8
。答案 0 :(得分:1)
application Documents
目录,适用于每个iOS版本:
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
答案 1 :(得分:1)
以下访问文档目录的代码在iOS 8中运行良好。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directory =
[[fileManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];