从NSURL下载后,iOS UIImage返回null

时间:2012-05-18 17:26:16

标签: ios for-loop uiimage nsdata nsurl

我有一个循环遍历一个url数组,然后从这些url中保存图像。这一切都正常,直到最后一个返回空图像的图像。我已经验证了网址是正确的,并在我在网络浏览器中访问时显示图像。我不知道我在哪里出错了。

这是循环:

-(void) downloadImages {
NSString *filePath;

NSLog(@"About to start loop");
for (int i = 0; i < urls.count; i++) {
    NSLog(@"Downloading: %@", [names objectAtIndex:i]);

    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [urls objectAtIndex:i]]]]];

    filePath = [NSString stringWithFormat:@"%@/images/%@.png", [[MakeAMemeIAPHelper sharedHelper] getDocumentsFolder], [names objectAtIndex:i]];
    NSLog(@"Saving: %@", [names objectAtIndex:i]);

    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
    [imageData writeToFile:filePath atomically:YES];

    progress += 0.1;
    [self updateProgress];
}
NSLog(@"Done with loop");
}

0 个答案:

没有答案