0

我有一个循环遍历一组 url,然后从这些 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");
}
4

0 回答 0