这是我正在使用的代码,它可以在模拟器中运行,但在idevice中没有显示任何内容。如果我通过ifunbox添加文件夹或文件,它会显示在设备中。我是否需要任何创建或添加文件的权限?
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"/Folders/%@", self.txtFolder.text]];
NSLog(@"%@", dataPath);
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
{
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
[sec1Contents addObject:self.txtFolder.text];
sec1 = [NSArray arrayWithArray:sec1Contents];
[self.tblFiles reloadData];
}
提前感谢。
答案 0 :(得分:0)
Use this code :
NSURL *allitemsImageurl =[NSURL URLWithString: url];
NSData *allItemsImageData = data1; // Load XML data from web
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectoryPath = [paths objectAtIndex:0];
NSString *st1=[ @"img_" stringByAppendingString:[NSString stringWithFormat:@"%d.png",imageCount]];
NSString *allitemsImagePath = [documentsDirectoryPath stringByAppendingPathComponent:st1];
NSLog(@"%@",allitemsImagePath);
[allItemsImageData writeToFile:allitemsImagePath atomically:TRUE];