Code Monkey home page Code Monkey logo

Comments (14)

marty-suzuki avatar marty-suzuki commented on May 27, 2024 1

Would you try to add embeddedView.cancelLoad() before removeFromSuperview?

from urlembeddedview.

marty-suzuki avatar marty-suzuki commented on May 27, 2024 1

I've recognized what is wrong.
URL host of your screenshots are m.youtube.com.
You need to replace m.youtube.com to www.youtube.com.
So your code should be like this.

let extractedUrls = sosReplyComment.comment.extractURLs()
for extractedUrl in extractedUrls {
    let url: URL
    if extractedUrl.host?.contains("m.youtube.com") == true {
        var components = URLComponents(string: extractedUrl.absoluteString)
        components?.host = "www.youtube.com"
        if let _url = components?.url {
            url = _url
        } else {
            url = extractedUrl
        }
    } else {
        url = extractedUrl
    }

    for view in cell.urlPreviewViewOutlet.subviews {
        if let ev = view as? URLEmbeddedView {
            ev.cancelLoad()
            ev.removeFromSuperview()
        }
    }
                
    let embeddedView = URLEmbeddedView()
    embeddedView.loadURL(url.absoluteString)
    embeddedView.borderColor = .clear
    embeddedView.cornerRaidus = 0
    embeddedView.frame = CGRect(x: 0, y:0, width: cell.frame.width - 20, height: 60)
    embeddedView.didTapHandler = { [weak self] _, url in
        guard let url = url else { return }
        self?.present(SFSafariViewController(url: url), animated: true, completion: nil)
    }
                
    cell.urlPreviewViewOutlet.addSubview(embeddedView)
    cell.urlViewHeightConstarint.constant = 61
                
    break
}

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024 1

Thank you very much @marty-suzuki. I will update the code and let you know if its going somewhere wrong

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024 1

@marty-suzuki Thank you very much brother, for your library and support now its working awesome :) 💯

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024

Sorry now I'm able to update the pod using
pod "URLEmbeddedView", '0.10.2' command
But still loading the Youtube thumbnails is not working for me with the updated code

from urlembeddedview.

marty-suzuki avatar marty-suzuki commented on May 27, 2024

Could you paste that youtube link?

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024

@marty-suzuki Hi Sorry for the late reply. And thanks for your reply :)

 let extractedUrl = sosReplyComment.comment.extractURLs()
            for url:URL in extractedUrl{
                for view in cell.urlPreviewViewOutlet.subviews {
                    if view is URLEmbeddedView{
                        view.removeFromSuperview()
                    }
                }
                
                let embeddedView:URLEmbeddedView = URLEmbeddedView()
                embeddedView.loadURL(url.absoluteString)
                embeddedView.borderColor = UIColor.clear
                embeddedView.cornerRaidus = 0
                embeddedView.frame = CGRect(x: 0, y:0, width: Int(cell.frame.width-20), height: 60)
                embeddedView.didTapHandler = { [weak self] embeddedView, URL in
                    guard let URL = URL else { return }
                    self?.present(SFSafariViewController(url: URL), animated: true, completion: nil)
                }
                
                cell.urlPreviewViewOutlet.addSubview(embeddedView)                
                break
            }

This is how I'm using your URLEmbeddedView to show hyperlink with a thumbnail in my UITableviewCells. But it is working perfectly sometime in my iPhone 5 but not in iPads and iPhone 6s plus. Most probably I might be doing something wrong in code

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024
  let extractedUrl = sosReplyComment.comment.extractURLs()
            for url:URL in extractedUrl{
                for view in cell.urlPreviewViewOutlet.subviews {
                    if view is URLEmbeddedView{
                        view.removeFromSuperview()
                    }
                }
                
                let embeddedView:URLEmbeddedView = URLEmbeddedView()
                embeddedView.cancelLoad()
                embeddedView.loadURL(url.absoluteString)
                embeddedView.borderColor = UIColor.clear
                embeddedView.cornerRaidus = 0
                embeddedView.frame = CGRect(x: 0, y:0, width: Int(cell.frame.width-20), height: 60)
                embeddedView.didTapHandler = { [weak self] embeddedView, URL in
                    guard let URL = URL else { return }
                    self?.present(SFSafariViewController(url: URL), animated: true, completion: nil)
                }
                
                cell.urlPreviewViewOutlet.addSubview(embeddedView)
                cell.urlViewHeightConstarint.constant = 61
                
                break
            }

Added after removing the view but no change with it. but it was sometimes working in iPhone 5, not in other devices.

from urlembeddedview.

marty-suzuki avatar marty-suzuki commented on May 27, 2024

that is wrong addtion.
i mean like this.

for view in cell.urlPreviewViewOutlet.subviews {
    if let embeddedView = view as? URLEmbeddedView {
        embeddedView.cancelLoad()
        embeddedView.removeFromSuperview()
    }
}

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024

Just now i tried that as well but not working :(

  let extractedUrl = sosReplyComment.comment.extractURLs()
            let embeddedView:URLEmbeddedView = URLEmbeddedView()
            for url:URL in extractedUrl{
                for view in cell.urlPreviewViewOutlet.subviews {
                    if view is URLEmbeddedView{
                        embeddedView.cancelLoad()
                        view.removeFromSuperview()
                    }
                }

The code change is posted above. and I tried with the exact same code what u pasted also. Only for Youtube links we are facing this problem other than that most of the links are returning thumbnails and working fine

from urlembeddedview.

marty-suzuki avatar marty-suzuki commented on May 27, 2024

embeddedView and view is not same instance in the code posted above, therefore that code is wrong.
Could you paste URLs that is not loaded?
Or could you check open graph data with this link.
https://www.youtube.com/oembed?url=xxx

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024

Not single URL. All youtube URL's are not loading its thumbnails.
Tried with the sample that mentioned in the comment also

from urlembeddedview.

marty-suzuki avatar marty-suzuki commented on May 27, 2024

Sorry, i can not investigate without information such as url sample.

from urlembeddedview.

sarathdev avatar sarathdev commented on May 27, 2024

@marty-suzuki thanks for your valuable time and replies. But the problem I'm facing is I have tried many of youtube links and no youtube links returned thumbnails for me. But these same returned once in iPhone 5 but not working always. Attaching some of the screenshots and URLs for your reference, please check and let me know what I'm doing wrong here.

The attached screenshots are from the iPhone 6s plus and from the iPad Air.

https://www.youtube.com/watch?v=C0DPdy98e4c

https://www.youtube.com/watch?v=PCwL3-hkKrg
screen shot 2017-10-18 at 11 02 36 am

screen shot 2017-10-18 at 11 02 36 am
screen shot 2017-10-16 at 12 38 23 pm

from urlembeddedview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.