在iOS App中预览嵌入式链接就像Facebook一样 [英] Preview Embedded Links in iOS App Like Facebook

查看:116
本文介绍了在iOS App中预览嵌入式链接就像Facebook一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图以与Facebook相同的方式在iOS应用程序中嵌入链接预览:





我正试图找到一种方法来获取最合适的图像(和返回网址,网页标题,甚至是元描述并将其传回给应用程序,但我不确定最佳方式。



有一些API可以做到这一点,大部分价格,但似乎不应该这么困难。有什么想法?

解决方案

您可以在服务器端或客户端执行此操作。



服务器端,您可以使用脚本(如您构建的脚本)来获取HTML页面的< head> 标记。 / p>

客户端你可以用NSURLConnection或像AFNetworking这样的库下载整个页面作为HTML(例如,Mashable是大约180KB),并用XML解析器解析它找到< head> 标记。



我建议你创建一个服务器脚本,这样你就可以重用它了在其他项目或其他平台上。


I'm trying to embed a link preview in an iOS application in the same way that Facebook does:

I'm trying to figure a way to grab the most suitable image (and return the url to it), the page title, and maybe even a meta description and pass it back to the application, but I'm unsure of the best way.

There are API's that do this, most for a price, but it seems like it should not be this difficult. Any thoughts?

解决方案

You can do this server-side or client-side.

Server-side, you can use a script (like the one you've built) to grab the <head> tag of the HTML page.

Client-side you can download the whole page as HTML (as an example, Mashable is ~180KB) with NSURLConnection or a library like AFNetworking and parse it with a XML parser to find the <head> tag.

I suggest you to create a server script, so you can reuse it in other projects or other platforms.

这篇关于在iOS App中预览嵌入式链接就像Facebook一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆