Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Current URL (UIWebView)

Simply enough, I need to know how to obtain the current URL that the UIWebView is in. That way, I would be able to add such features as bookmarking, sharing, etc.

The crux of the question is, what can I do to obtain the current URL of the webvew?

EDIT: Solution:

NSString *currentURL = myWebView.request.URL.absoluteString;
like image 806
JTApps Avatar asked Jan 16 '12 04:01

JTApps


3 Answers

NSString *currentURL = myWebView.request.URL.absoluteString;
like image 84
Raptor Avatar answered Oct 19 '22 06:10

Raptor


[[[web request] URL] absoluteString]

Will give you the current url as a String.

like image 4
Ecarrion Avatar answered Oct 19 '22 06:10

Ecarrion


In Swift if you need to get your URL you need to write this block of code:

func webViewDidFinishLoad(webView: UIWebView) {
    let currentURL = webView.request?.mainDocumentURL
    print(currentURL)
}
like image 2
Den Avatar answered Oct 19 '22 08:10

Den