Need help with UIwebView

Discussion in 'iOS Development' started by bobby456, Dec 29, 2009.

  1. bobby456

    bobby456 New Member

    Joined:
    Jan 26, 2008
    Messages:
    6
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Hi,
    I'm using an action button to open a url to safari. But this method makes the user to leave my app...
    [OBJC]
    - (IBAction) video: (id)sender {

    NSString *string = [webView stringByEvaluatingJavaScriptFromString:
    @"document.body.innerHTML.substring(document.bo dy. innerHTML.lastIndexOf('embed src=')+11, "];
    fileURL = [NSURL URLWithString:string];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: string]];
    [/OBJC]

    So I tried this..
    [OBJC]
    - (IBAction) video: (id)sender {

    NSString *string = [webView stringByEvaluatingJavaScriptFromString:
    @"document.body.innerHTML.substring(document.bo dy. innerHTML.lastIndexOf('embed src=')+11, "];
    fileURL = [NSURL URLWithString:string];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
    [/OBJC]

    When I use that and I click on the action button I have a blank page when there is no embed video.
    Not like ..

    [OBJC]
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: string]];[/OBJC]
    When there was no embed video, the button didn't do anything.

    So what should I use to don't have the blank page and without leaving my app?

    Thank you
  2. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Off-topic: Are trying to rip videos from iPhone streaming sites (spcentral.org, etc.) or something?

    On-topic: Try debugging your code (NSLog) and see if your JavaScript actually retrieves the correct URL. If it does, then UIWebView (in your context) probably can't play movie files. Use MPMoviePlayer and initialize it with the URL you retrieved.
  3. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Don't edit out your question, it's the most useless thing you can do. I hope a mod comes and puts it back.. hint hint.
  4. jchaike

    jchaike Active Member

    Joined:
    Dec 26, 2007
    Messages:
    1,260
    Likes Received:
    3
    Device:
    iPhone 4 (Black)
    is there a way to do what this person wanted to do, except not with videos.

    I have a UITableView and it has website names listed, I want to open the selected website in a UIWebView, but I need to have the http://www. added to it, how would i produce a variable that would let me do that, and open it in a UIWebView
    I have tried NSArray and tried having @"http://www.", selectedCountry

    (Selectedcountry is the name of my variable)

    I also cant seem to get my WebViewController to show the requested URL using the variables.

    Any help is greatly appreciated.
  5. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Theoretically, this would work:
    [OBJC]NSString *urlString = [@"http://www." stringByAppendingString: selectedCountry]; // or something along the lines, then use [NSURL URLWithString: urlString] [/OBJC]
    But it's really not the optimal approach. What you should be doing is making some kind of 'data model' class that represents a website, and let it have several properties like its name, URL, (potentially an icon or something), & UUID. Then you should load that data from a plist. (I don't like hard-coding things, so this is probably what I would do)
  6. jchaike

    jchaike Active Member

    Joined:
    Dec 26, 2007
    Messages:
    1,260
    Likes Received:
    3
    Device:
    iPhone 4 (Black)
    This helped me a lot, thanks!

    I just have one more thing. I made html pages that I want to be loaded locally from the application through a UIWebView. I am able to load the files, but the Javascript and CSS files dont load properly. How can I fix this?

    Thanks again!
    ------------------double post merged------------------
    --edit--
    I think i was able to just put the JS file into the HTML file, but now im having troubles displaying the images that are in the HTML file.

Share This Page