In both chat apps, social apps have a feature, when we paste a link on text view it's giving us a thumbnail from that url,
Is this possible to do in an iOS app. If it is how may I do this?
In both chat apps, social apps have a feature, when we paste a link on text view it's giving us a thumbnail from that url,
Is this possible to do in an iOS app. If it is how may I do this?
I would parse html content and try to find links to .png, jpg etc files. Then check the resolution to exclude very small images or those specified as a background in css. As a result a user would get a list of filtered images like on the screenshot you attached.
As a parser you could use https://github.com/nolanw/HTMLReader
Pages like Facebook use OpenGraph information from web pages to generate thumbnails for links. OpenGraph attributes describe the object presented on a web page. OpenGraph data is stored in meta tags, as shown in A.Krasniqi's answer:
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
These meta tags have a prefix of og
.
Basic OpenGraph attributes include:
Other tags include:
All OpenGraph parameters are documented here
To parse these, you can use NSXMLParser
but others have implemented OpenGraph parsers. (Just google "iOS OpenGraph parser")
Updated: For new iOS devs, you could use: https://github.com/itsmeichigo/URLPreview
Use opengraph from facebook, then parse it
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
I finally did it with MTDURLPreview on github
Usage
#import "MTDURLPreview.h"
[MTDURLPreview loadPreviewWithURL:@"url here" completion:^(MTDURLPreview *preview, NSError *error) {
NSLog(@"Image URL : %d", [preview.imageURL isEqual:[NSNull null]]);
NSLog(@"Content : %@", preview.content);
NSLog(@"Title : %@", preview.title);
}];
Hope your problem solved.
Here is the best solution I used and I get the good results.
Source code: https://github.com/keshiim/WBGLinkPreview
Cocoapod Name: pod "WBGLinkPreview"
I used code inside my class like:
#import <WBGLinkPreview/WBGLinkPreview.h>
@interface ViewController ()
{
WBGLinkPreview *urlPreview;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
urlPreview = [[WBGLinkPreview alloc] init];
[urlPreview previewWithText:@"https://www.youtube.com/watch?v=HHq_ChsWtb0"
onSuccess:^(NSDictionary *result) {
NSLog(@"Final Output:: %@", result);
} onError:^(WBGPreviewError *error) {
NSLog(@"%@", error.description);
}];
}