Randy Randy - 1 year ago 57
iOS Question

Can't do google search with "&" character on WKWebView

I have a

in my app that allows a user to search on Google.

Everything works fine but searches with "&" character. For instance, if I search for at&t, I will have the results of the search of at.

If I print the url of my web view in
, I can see the right searched terms at&t

func webView(webView: WKWebView, didCommitNavigation navigation: WKNavigation!)



We can see the q parameter :
whereas the result page is the same as the one for

Any ideas to solve that problem would be appreciated.

Answer Source

As this verifies, the & is not automatically escaped in the usual way, so you probably have to process your search string manually (wherever your user enters the terms, just replace the & when you get it from there):

let searchterm = getTermFromWherever()
let actualterm = searchterm.stringByReplacingOccurrencesOfString("&", withString: "%26")

This should work.