how to find the current URL from a UIWebView swift

How to find out the current url from UIWebView swift

Replies

I cannot find how to get that information from UIWebView (the request instance variable is nil when I look at it), but if you use WKWebView from the module WebKit, you can get the current url with the instance variable ".url". Is there any reason that you don't use WKWebView and can you switch easily to that?

It is actually possible to get it with UIWebView, but you have to use Javascript:


webview.stringByEvaluatingJavaScript(from: "document.URL")

What ahltorp said plus…

Unless you have specific reasons to stick with UIWebView, you should switch to WKWebView. WKWebView is the future, and UIWebView is very much the past.

OTOH, if you do have specific reasons to stick with UIWebView, I’d love to hear what they are.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"