d2burke d2burke - 4 months ago 31
iOS Question

Preview Embedded Links in iOS App Like Facebook

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

enter image description here

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?

Answer

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.