Get current URL from UIWebView

Discussion in 'iPhone/iPad Programming' started by newtoiphonesdk, Aug 21, 2010.

  1. macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    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
    Code:
    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.
    Code:
    - (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
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. macrumors newbie

    Joined:
    Aug 22, 2010
    #3
    right, so if you webview is called sermons, you just need to call sermons.request.URL.absoluteString to get the url string
     
  4. thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #4
    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 ?
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    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.
     
  6. macrumors newbie

    Joined:
    Aug 11, 2010
    Location:
    ...in the UK
    #6
    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.
     

Share This Page