我正在使用以下代码在单独的线程中将图像写入我的应用程序目录
for (int j =0; j<[sorted count]; j++) {
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[sorted objectAtIndex:j]]];
UIImage *image = [UIImage imageWithData:data];
if (image!=nil) {
NSLog(@"%@",[sorted objectAtIndex:j]);
[images addObject:image];
}
}
和
for (int k=0;k<[images count];k++)
{
NSString *temp = [[sorted objectAtIndex:k]lastPathComponent];
NSString *imagePath = [dataPath stringByAppendingPathComponent:temp];
NSData *data = UIImageJPEGRepresentation([images objectAtIndex:k], 1.0f);
[data writeToFile:imagePath atomically:YES];
}
但奇怪的是最后两张图片没有被写入我已经尝试了一切,但它似乎不起作用。有人对此有任何想法吗?