尝试使用此代码在后台下载图像
确保您的网址包含图片,并且该网址是有效的网址
NSString *strImgURLAsString = @"imageURL";
[strImgURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imgURL = [NSURL URLWithString:strImgURLAsString];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:imgURL] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
UIImage *img = [[UIImage alloc] initWithData:data];
// pass the img to your imageview
}else{
NSLog(@"%@",connectionError);
}
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9757 次 |
| 最近记录: |