PDA

View Full Version : Get current URL from UIWebView




newtoiphonesdk
Aug 21, 2010, 11:51 PM
I have been trying to get this setup so that I can this pass it to a MailComposer to email the content from mywebview. I found a blog that said to use this
NSString *currentURL
= myWebView.request.URL.absoluteString;
However, it doesn't say where to implement this at, or how/where to declare it. In the view controller I have this code currently running for the webview.
- (void)awakeFromNib
{
[sermons loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://theipadpreacher.wordpress.com"]]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];

}
I'd Like to be able to set up an emailcomposer sheet so that I could email the contents of this from the app, and I don't know if I'm missing something simple, or if I need to completely rewrite the webview part of the code and where to put the code for getting the current url from the webview. Thanks



robbieduncan
Aug 22, 2010, 02:16 AM
The blog that you copied the code from (apparently without bothering to understand it) called the variable that points at their webview "myWebView". You appear to have called your "sermons". It should be clear what you need to change.

robkwok
Aug 22, 2010, 04:15 AM
The blog that you copied the code from (apparently without bothering to understand it) called the variable that points at their webview "myWebView". You appear to have called your "sermons". It should be clear what you need to change.

right, so if you webview is called sermons, you just need to call sermons.request.URL.absoluteString to get the url string

newtoiphonesdk
Aug 22, 2010, 01:19 PM
The blog that you copied the code from (apparently without bothering to understand it) called the variable that points at their webview "myWebView". You appear to have called your "sermons". It should be clear what you need to change.

The blog I got it from had nothing in it but that one line of code. It was called get current URL in the blog title and all the article had was that one line of code. Where do I put the code in? In the same awakefromnib line of code ?

robbieduncan
Aug 22, 2010, 03:27 PM
The blog I got it from had nothing in it but that one line of code. It was called get current URL in the blog title and all the article had was that one line of code. Where do I put the code in? In the same awakefromnib line of code ?

Wherever it makes sense. Think about it. If you put it in awakefromnib you'll get the URL at that point in time. Which sounds wrong to me.

Anne R. Kist
Aug 22, 2010, 06:34 PM
Where do I put the code in? In the same awakefromnib line of code ?
awakefromnib sounds like an excellent place to put it. Don't forget to do a [sermons release] before to free up any extra memory that sermons might be using.