images from foursquare are NSURLErrorFileDoesNotExist = -1100

我怕爱的太早我们不能终老 提交于 2019-12-11 09:15:02

问题


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) {
    ;
}];


来源:https://stackoverflow.com/questions/27868247/images-from-foursquare-are-nsurlerrorfiledoesnotexist-1100

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!