images from foursquare are NSURLErrorFileDoesNotEx

2019-08-06 12:25发布

问题:

I am attempting to download an image from foursquare( sourced from using the venue api) and I keep getting NSURLErrorFileDoesNotExist = -1100, errors for trying to grab the image.

imageUrl = [NSURL URLWithString: [NSString stringWithFormat:
                                  [@"https://irs0.4sqi.net/img/general/720x400/1203715_jAVNrPE87IFuOUa69i1q5UXQ0bUAfjG8V-R_hBUL09c.jpg" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
//[cell.venueImageView sd_setImageWithURL:imageUrl placeholderImage:nil];
typeof(WHMDateListTableViewCell *) __weak weakCell = cell;
[cell.venueImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"create-profile-step-4-pic-box-reg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    weakCell.venueImageView.image = image;
}];

The image url loads fine in Chrome. I have also pulled other images from other web urls and it works fine.

回答1:

The issue was that the API was returning images with an https scheme. Once I manipulated the returned URL to be of http, instead of https then I was able to properly download the image for imageview display.

//setup Venue
NSURL *imageUrl;

imageUrl = [NSURL URLWithString:self.selectedDate.Venue.Media[indexPath.item]];

NSURLComponents *components = [NSURLComponents new];
components.scheme = @"http";
components.host = imageUrl.host;
components.path = imageUrl.path;

NSURL *url = [components URL];


[cell.photoImageView sd_setImageWithURL:url placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    ;
}];