B.Malka B.Malka - 25 days ago 7
Swift Question

Youtube videos cannot be played in UIWebView (iOS, Swift)

I think I know what was my problem but I couldn't find a solution for it.
On my app, you can see that there is a YouTube video, but when you click on it, it won't play the video. Here's the line of code that may cause the issue:

webView.loadHTMLString(partyRock.videoURL, baseURL: nil)

I think that sending nil to the baseURL may cause the issue, but I'm not sure what to replace with.



Why are you using loadHTMLString? This property sets the main page content and base URL and I don't think you want to do that.

Use this instead:

let requestURL = URL(string: partyRock.videoURL)
let request = URLRequest(url: requestURL!)