Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate thumbnail for preview of a url ios swift

I need to create a preview of the url with the thumbnail and some metadata with. How can i get the thumbnail of the url and metadata so that i generate a preview of the url. I have no idea how get thumbnail and metadata.I've searched for this, but could not get anything in iOS(not in objective or swift). I will be thankful for any useful links as well.

like image 565
Arun K Avatar asked Jan 24 '26 11:01

Arun K


1 Answers

You can use a preview i dont know if this is what you are expecting. In this example im downloading the preview of the metadata site. Then I have a UIView and adding in the MAIN THREAD with:

self?.viewContainer.addSubview(linkPreview)

I hope this will help you!

Your friendly Mexican neighbor R.A, Regards

import LinkPresentation

func fetchPreview(urlString: String){
        guard let url = URL(string: urlString) else {
            return
        }
        let linkPreview = LPLinkView()
        let provider = LPMetadataProvider()
        provider.startFetchingMetadata(for: url, completionHandler: {
            [weak self] metaData, error in
            guard let data = metaData, error == nil else{
                return
            }
            DispatchQueue.main.async {
                linkPreview.metadata = data
                self?.viewContainer.addSubview(linkPreview)
                linkPreview.frame = CGRect(x: 0, y: 0, width: 349, height: 245)
            }
            
        })
    }

Final result

like image 167
Roberto Abad Ramírez Avatar answered Jan 27 '26 01:01

Roberto Abad Ramírez