我一直在試圖從使用ASIHTTPRequest的URL加載圖像,但我總是想出一個空白的UIImage。我認爲這可能與iOS自動選擇@ 2x圖像版本或vica相關。如何使用ASIHTTPRequest @ 2x填充UIImage視圖?
[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]);
沒有我做的,包括在服務器上命名的圖像@ 2倍或提供兩個版本,得到它加載。有任何想法嗎?有沒有人做過這個?當我在本地加載它們時(從包中)我沒有任何問題。
謝謝!
EDIT
這裏的日誌輸出
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/[email protected]
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] /用戶/ jonathantpage /庫/應用程序支持/ iPhone模擬器/ 4.3 /應用/ A17C0938-D2ED-447C-BD17-94726C5E5A66 /圖書館/緩存/ ASIHTTPRequestCache/PermanentStore/FE05295C8CD7687DC7A505C9070B6FC7.png
我檢查了本地文件路徑,它在那裏(和正確的視網膜大小的圖像)。 – 2011-03-19 16:48:14