UIWebView to browse local files

Discussion in 'iOS Programming' started by dusker, Jun 2, 2009.

  1. dusker macrumors member

    Joined:
    May 31, 2009
    #1
    Hi Everyone,
    i have a following problem:
    i'd like to build a simple offline webpage browser, the webpage is pure HTM files. The structure looks like this:

    index.htm
    /subpages/page1.htm
    /subpages/page2.htm

    Ofcourse there're a lot of subpages not just two, and here's my question. I'm able to load the index htm into UIWebView using loadrequest, but index.htm contains links to subpages in a form of <a href="subpages/page1.htm">page1</a> and those links won't work. Can anyone help out?

    thanks for help in advance
    peter
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    Did you create that directory structure wherever you put your files? (bundle or sandbox Documents directory)?
     
  3. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #3
    Look at the UIWebViewDelegate's shouldLoadRequest method. When they click on the link this gets called and you load the new htm file into it yourself.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    I think you need to specify the baseURL in one of the methods that takes that parameter to load your index.htm file.
     
  5. dusker thread starter macrumors member

    Joined:
    May 31, 2009
    #5
    what do you mean yourself? if the two htm files are in rood directory of a bundle hyperlinks work perfectly. issues are when the folders get involved.

    i just dragged and dropped the folder into resources in xcode

    how to specify baseUrl in loadrequest method?
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
  7. dusker thread starter macrumors member

    Joined:
    May 31, 2009
    #7
    Hi,
    thanks for all the answers so far.
    Would you mind providing me with one hint, meaningly what other method would allow me to load html file into uiwebview?
    greetings
    peter
     
  8. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #8
    That doesn't, by itself, create the directories you need.
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    Um, loadHTMLString:baseURL: and loadData:MIMEType:textEncodingName:baseURL:
     

Share This Page