0
我有一个特殊的URL,它在浏览器中返回图片。我想把这个特殊的图像放入UIImage对象中。但是,在我下面的代码示例中,似乎返回的数据不是图像。无法使用NSURLConnection从网址获取图片sendSynchronousRequest
浏览器似乎知道图像,我怎么能到图像?
是的,我需要通过proxify代理服务器获取此映像来解决我们有的问题。
以下是示例代码。
-(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;
}