Get a Thumb image and the name of a specific site URL in iOS?

enter image description here

Do I need to display a thumb image and get the name of the WEB URL just like the LinkedIN app and Skype app in iOS?

Is there a solution?

+5
source share
7 answers

URLEmbeddedView written in Swift, but you can use it in Objective-C.

This is an Objective-C code sample. Please, check him.

#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 
+1
source

Here is the easiest way to find the URL icon icon

 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]; 

Quick 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)! 

Can this help?

UPDATE

Below is a quick library that helps you upload images as you want.

URLEmbeddedView

Here you can check the actual operation of the library.

+5
source

You can refer to this: "NSURL extension to display web browsing information" 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 } } }) } 
+1
source

you need to load the website html and then parse it for the <title> (which gives you the name)

and the <link rel="icon" ... > that Favicon gives you. Wikipedia article on Favicon link

Please note that neither the name nor the icon is guaranteed, although most sites provide a title, and most of the main ones provide Favicon.

0
source
  • Download homepage
  • Metadata analysis for example og: image and og: url
  • Their content is what you need.
0
source

Other answers are correct, but it is worth noting that favicon is 16x16 pixels or 32x32 pixels. This is probably not enough for size and resolution.

There is no tutorial for this, but one way could be to send a google request for the site name + "icon" (for example, the "Facebook" icon) and select the first result.

Regarding the name of the website, if you are looking for the name displayed in your browser when you enter the site, you need to parse the html looking for the <title> </title> .

Reaching both of them can be difficult, but it is definitely not impossible. There may be some service that provides this, but as far as I know.

0
source

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 
0
source

Source: https://habr.com/ru/post/1245999/


All Articles