Comments (14)
Would you try to add embeddedView.cancelLoad()
before removeFromSuperview?
from urlembeddedview.
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.
Thank you very much @marty-suzuki. I will update the code and let you know if its going somewhere wrong
from urlembeddedview.
@marty-suzuki Thank you very much brother, for your library and support now its working awesome :) 💯
from urlembeddedview.
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.
Could you paste that youtube link?
from urlembeddedview.
@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.
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.
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.
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.
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.
Not single URL. All youtube URL's are not loading its thumbnails.
Tried with the sample that mentioned in the comment also
from urlembeddedview.
Sorry, i can not investigate without information such as url sample.
from urlembeddedview.
@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
from urlembeddedview.
Related Issues (20)
- Value of type 'Any' has no member '1' HOT 1
- OpenGraphData fields are not visible in ObjC HOT 12
- OG data is not fully parsed HOT 6
- Page description is not available HOT 3
- Unreadable characters in link title.
- Error with addPersistentStoreWithType
- Support Swift 4.2 HOT 1
- Not able to show thumbnails of youtube links. HOT 1
- Google maps thumbnail missing
- OG data not read properly on certain sites HOT 6
- redirect
- Crash on fetch HOT 7
- Swift 5 support HOT 4
- README.md typo in Swift
- Crashes on load frequently
- Does not load imageURL or title for basic websites HOT 2
- Pod install fails on macOS 10.15 HOT 1
- pod fixes HOT 1
- Can you provide steps to install pod for objective c project?
- Add - SPM Support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from urlembeddedview.