Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related to issue number #39 #44

Closed
sarathdev opened this issue Oct 13, 2017 · 14 comments
Closed

Related to issue number #39 #44

sarathdev opened this issue Oct 13, 2017 · 14 comments

Comments

@sarathdev
Copy link

Hi, Suzuki Sorry to bother you again, How can I update to the specific version of the pod you specified in that bug number #39.
I tried updating to the latest version (0.12.0).
But it won't help for me because I'm using 8.3.3 and the pod is upgraded for Swift 4

@sarathdev
Copy link
Author

sarathdev commented Oct 13, 2017

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

@marty-suzuki
Copy link
Owner

Could you paste that youtube link?

@sarathdev
Copy link
Author

sarathdev commented Oct 16, 2017

@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

@marty-suzuki
Copy link
Owner

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

@sarathdev
Copy link
Author

sarathdev commented Oct 17, 2017

  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.

@marty-suzuki
Copy link
Owner

that is wrong addtion.
i mean like this.

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

@sarathdev
Copy link
Author

sarathdev commented Oct 17, 2017

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

@marty-suzuki
Copy link
Owner

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

@sarathdev
Copy link
Author

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

@marty-suzuki
Copy link
Owner

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

@sarathdev
Copy link
Author

sarathdev commented Oct 18, 2017

@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

@marty-suzuki
Copy link
Owner

marty-suzuki commented Oct 18, 2017

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
}

@sarathdev
Copy link
Author

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

@sarathdev
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants