【发布时间】:2011-07-18 19:17:06
【问题描述】:
我一直在尝试使用 ASIHTTPRequest 从 url 加载图像,但我总是想出一个空白的 UIImage。我认为这可能与 iOS 自动选择图像的 @2x 命名版本有关,反之亦然。
[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];
NSString *url_string = [NSString stringWithFormat:@"http://173.246.100.185/%@", [eventDictionary objectForKey:kEventDescriptionImageURLKey]];
NSURL *url = [NSURL URLWithString:url_string];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setSecondsToCache:86400];
[request setDelegate:self];
[request setCompletionBlock:^{
NSLog(@"Successful Update");
[self makeAssignment];
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"%@", [error localizedDescription]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Update Failed"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}];
[request startAsynchronous];
NSLog(@"%@", url_string);
makeAssignment 方法如下。
NSString *url_string = [NSString stringWithFormat:@"http://173.246.100.185/%@", [eventDictionary objectForKey:kEventDescriptionImageURLKey]];
NSURL *url = [NSURL URLWithString:url_string];
downloadedImage = [[UIImage alloc] initWithContentsOfFile:[[ASIDownloadCache sharedCache] pathToCachedResponseDataForURL:url]];
NSLog(@"%@", downloadedImage);
NSLog(@"%@", [[ASIDownloadCache sharedCache] pathToCachedResponseDataForURL:url]);
我所做的任何事情,包括在服务器上命名图像@2x 或提供两个版本,都无法加载它。有任何想法吗?有没有人这样做过?当我在本地(从包内)加载它们时,我没有任何问题。
谢谢!
编辑
这是日志输出
2011-03-19 11:46:11.088 clv[82974:207] 更新成功
2011-03-19 11:46:12.822 clv[82974:207] http://173.246.100.185/ying_yang_concert@2x.png
2011-03-19 11:46:12.844 clv[82974:207] >
2011-03-19 11:46:12.913 clv[82974:207] 更新成功
2011-03-19 11:46:12.932 clv[82974:207]
2011-03-19 11:46:12.932 clv[82974:207] /Users/jonathantpage/Library/Application Support/iPhone Simulator/4.3/Applications/A17C0938-D2ED-447C-BD17-94726C5E5A66/Library/Caches/ ASIHTTPRequestCache/PermanentStore/FE05295C8CD7687DC7A505C9070B6FC7.png
【问题讨论】:
标签: iphone ios uiimageview uiimage asihttprequest