I have to display thumb image and get title of WEB URL same as LinkedIN app and Skype app in iOS?
Is there any Solution?
I have to display thumb image and get title of WEB URL same as LinkedIN app and Skype app in iOS?
Is there any Solution?
URLEmbeddedView written in Swift, but you can use in Objective-C.
This is Objective-C sample code. Please check it.
#import <URLEmbeddedView/URLEmbeddedView-Swift.h>
#import <MisterFusion/MisterFusion-Swift.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) URLEmbeddedView *embeddedView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.textView.text = @"https://github.com/";
[OGDataProvider sharedInstance].updateInterval = [NSNumber days:10];
self.embeddedView = [[URLEmbeddedView alloc] initWithUrl:@""];
[self.containerView addLayoutSubview:self.embeddedView andConstraints:@[
self.embeddedView.Top,
self.embeddedView.Right,
self.embeddedView.Left,
self.embeddedView.Bottom
]];
}
- (IBAction)didTapFetchButton:(id)sender {
[self.embeddedView loadURL:self.textView.text completion:nil];
}
@end
Here is the easiest way to find the favicon icon of URL
NSString *myURLString = @"http://www.google.com/s2/favicons?domain=www.facebook.com";
NSURL *myURL=[NSURL URLWithString: myURLString];
NSData *myData=[NSData dataWithContentsOfURL:myURL];
UIImage *myImage=[[UIImage alloc] initWithData:myData];
Swift Version:
let myURLString = "http://www.google.com/s2/favicons?domain=www.facebook.com"
let myURL = NSURL(string: myURLString)!
let myData = NSData.dataWithContentsOfURL(myURL)
let myImage = UIImage(data: myData)!
May this helps lot
UPDATE
Below is the swift library which helps to load images like you want.
URLEmbeddedView written in Swift, but you can use in Objective-C.
This is Objective-C sample code. Please check it.
#import <URLEmbeddedView/URLEmbeddedView-Swift.h>
#import <MisterFusion/MisterFusion-Swift.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) URLEmbeddedView *embeddedView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.textView.text = @"https://github.com/";
[OGDataProvider sharedInstance].updateInterval = [NSNumber days:10];
self.embeddedView = [[URLEmbeddedView alloc] initWithUrl:@""];
[self.containerView addLayoutSubview:self.embeddedView andConstraints:@[
self.embeddedView.Top,
self.embeddedView.Right,
self.embeddedView.Left,
self.embeddedView.Bottom
]];
}
- (IBAction)didTapFetchButton:(id)sender {
[self.embeddedView loadURL:self.textView.text completion:nil];
}
@end
You can refer this: "An NSURL extension for showing preview info of webpages" https://www.cocoacontrols.com/controls/urlpreview
func fetchPageInfo(completion: ((title: String?, description: String?, previewImage: String?) -> Void), failure: ((errorMessage: String) -> Void)) {
let request = NSMutableURLRequest(URL: self)
let newUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36"
request.setValue(newUserAgent, forHTTPHeaderField: "User-Agent")
ValidationQueue.queue.cancelAllOperations()
NSURLConnection.sendAsynchronousRequest(request, queue: ValidationQueue.queue, completionHandler: { (response: NSURLResponse?, data: NSData?, error: NSError?) -> Void in
if error != nil {
dispatch_async(dispatch_get_main_queue(), {
failure(errorMessage: "Url receive no response")
})
return
}
if let urlResponse = response as? NSHTTPURLResponse {
if urlResponse.statusCode >= 200 && urlResponse.statusCode < 400 {
if let data = data {
if let doc = Kanna.HTML(html: data, encoding: NSUTF8StringEncoding) {
let title = doc.title
var description: String? = nil
var previewImage: String? = nil
print("title: \(title)")
if let nodes = doc.head?.xpath("//meta").enumerate() {
for node in nodes {
if node.element["property"]?.containsString("description") == true ||
node.element["name"] == "description" {
print("description: \(node.element["content"])")
description = node.element["content"]
}
if node.element["property"]?.containsString("image") == true &&
node.element["content"]?.containsString("http") == true {
previewImage = node.element["content"]
}
}
}
dispatch_async(dispatch_get_main_queue(), {
completion(title: title, description: description, previewImage: previewImage)
})
}
}
} else {
dispatch_async(dispatch_get_main_queue(), {
failure(errorMessage: "Url received \(urlResponse.statusCode) response")
})
return
}
}
})
}
you'll need to download the html of the site, then parse it for the <title>
tag (which gives you the title)
and the <link rel="icon" ... >
tag which gives you the Favicon.
Wikipedia article on Favicon link
Note that neither the title, nor the favicon are guaranteed to exist, though most sites do provide a title, and most major ones to provide a Favicon.
The other answers are correct, however it's worth noting that a favicon is either 16x16 pixels or 32x32 pixels. This is probably not sufficient for the size and resolution you wish to achieve.
There is no textbook way to achieve this, but one way could be to send a request to google for the website title + " icon" (for example "Facebook icon"), and pick the first result.
As for the title of the website, if you're looking for the title displayed in your browser when you enter the website you have to parse the html looking for the <title> </title>
tag.
Achieving both of this could prove challenging, but it's definitely not impossible. There might be some sort of service out there that provides this, but not to my knowledge.
I tried this library and it works for youtube, flipkart.
https://github.com/myell0w/MTDURLPreview
[MTDURLPreview loadPreviewWithURL:[NSURL URLWithString:@"http://www.flipkart.com"] completion:^(MTDURLPreview *preview, NSError *error) {
}];
Printing description of preview->_title:
Online Shopping India | Buy Mobiles, Electronics, Appliances, Clothing and More Online at Flipkart.com
Printing description of preview->_domain:
www.flipkart.com
Printing description of preview->_imageURL:
http://img1a.flixcart.com/www/promos/new/20160701_015447_730x300_monsoon.jpg
© 2022 - 2024 — McMap. All rights reserved.