我有一个在浏览器中返回图像的特殊 URL。我想把这个特殊的图像放入 UIImage 对象中。但是,在我下面的代码示例中,返回的数据似乎不是图像。
浏览器似乎知道图像,我怎样才能得到图像?
是的,我需要通过代理代理服务器获取此图像来解决我们遇到的问题。
这是示例代码。
-(UIImage*)retrieveMap
{
NSString* proxifiedGoogleMapURL = @"http://proxify.com/p/011010A1000100/687474703a2f2f6d6170732e676f6f676c652e636f6d2f6d6170732f6170692f7374617469636d61703f63656e7465723d34312e3031343130312c2d3130342e393738333333267a6f6f6d3d362673697a653d35303678353036267363616c653d32266d6170747970653d726f61647326666f726d61743d706e672673656e736f723d66616c7365";
NSURLRequest * firstRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: proxifiedGoogleMapURL]];
NSURLResponse * firstResponse = nil;
NSError * firstError = nil;
NSData* firstData = [NSURLConnection sendSynchronousRequest:firstRequest returningResponse:&firstResponse error:&firstError];
UIImage* dataAsImage = [UIImage imageWithData:firstData];
if(firstError != nil || dataAsImage == nil)
{
NSLog(@"Failed in retrieving the map");
}
else
{
NSLog(@"Succeeded in retrieving the map");
}
return dataAsImage;
}