Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImage:如何获取网站选项卡图标_Ios_Uiimageview_Favicon_Rss Reader - Fatal编程技术网

Ios UIImage:如何获取网站选项卡图标

Ios UIImage:如何获取网站选项卡图标,ios,uiimageview,favicon,rss-reader,Ios,Uiimageview,Favicon,Rss Reader,我正在开发一个RSS阅读器,我需要为每个提要获取favicon。例如,如果我的feed是google.com,我希望得到“G”图标并将其放入UIImage或其他东西中。关于如何实现这一点有什么想法吗?最简单的方法是使用谷歌: NSString *myURLString = @"http://www.google.com/s2/favicons?domain=www.stackoverflow.com"; NSURL *myURL=[NSURL URLWithString: myURLString

我正在开发一个RSS阅读器,我需要为每个提要获取favicon。例如,如果我的feed是google.com,我希望得到“G”图标并将其放入UIImage或其他东西中。关于如何实现这一点有什么想法吗?

最简单的方法是使用谷歌:

NSString *myURLString = @"http://www.google.com/s2/favicons?domain=www.stackoverflow.com";
NSURL *myURL=[NSURL URLWithString: myURLString];
NSData *myData=[NSData dataWithContentsOfURL:myURL];

UIImage *myImage=[[UIImage alloc] initWithData:myData];
这应该行得通


您只需替换您想要查询图标的域。

如果您想要favicon,请尝试调用此URL:
http://www.google.com/s2/favicons?domain=
从您的应用程序中:

[NSURLConnection connectionWithRequest:
    [NSURLRequest requestWithURL:
        [NSURL URLWithString:@"http://www.google.com/s2/favicons?domain=google.com"]]
                              delegate:self];
否则,RSS频道的元数据有一个可选元素,
,如下所述:

例如:

<channel>
    <language>en-us</language>
        <title>Scientific American - News</title>
            <image>
                <title>Scientific American</title>
                <link>http://www.scientificamerican.com</link>
                <width>144</width>
                <url>
                    http://www.scientificamerican.com/media/logo/SAlogo_144px.gif
                </url>
                <height>45</height>
            </image>
        ...

美国英语
科学美国人-新闻
科学美国人
http://www.scientificamerican.com
144
http://www.scientificamerican.com/media/logo/SAlogo_144px.gif
45
...

此图像通常比站点的favicon大,可能不是正方形,但通过一些巧妙的裁剪和缩放,如果提要的favicon不可用,它可以作为图标使用。

如果将图像保存到桌面

1) 将图像拖到xcode中 2) 转到界面生成器 3) 选择UIImage后转到identity inspector 4) 在
图像
下拉框下,选择图像的名称


希望有帮助

这曾经有用!无论如何,我今天尝试了它,它返回了如下错误:error Domain=NSCocoaErrorDomain Code=256“无法打开文件”favicon。“苹果不建议使用UserInfo=0x10a1e4150{NSURL=}dataWithContentsOfURL。这是一个同步过程,并且阻止了慢速互联网的执行。你能告诉我怎样才能同时获得标题吗。