sulabh sulabh - 9 months ago 75
Swift Question

URL Encoding issue in swift ios

I am getting url from my server response as:


and i am doing encoding as :

videoURL = videoURL.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!

but avplayer not able to play this particular url .
seems like some issue in encoding URL


Your URL is already percent-encoded.

If you encode it again, the percent parts will be encoded twice, giving an invalid URL.

You can see that by removing the percent encoding from your URL and setting it again:

let base = "https://baseURL/The+Man+in+the+High+Castle+Official+Trailer+%E2%80%93+2+th.m3u8"
let decoded = base.stringByRemovingPercentEncoding!
let encoded = decoded.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLFragmentAllowedCharacterSet())!