Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-19-2008, 04:26 PM   #1 (permalink)
I can't think without pen
 
Join Date: Jul 2008
Location: New York
Posts: 72
Default How can I access local html file using UIWebView

Hi, I just watched the UIWebView tutorial, which was really great! But I want to load html file from the local project folder, not from internet. How can I do that? I understand I only need to change the following line:
Code:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];
I am assuming there about fileURLWithPath class function of the NSURL, but I don't know the absolute path of the project folder and how to reference a file from it.

Thanks for help!!
aahmed753 is offline   Reply With Quote
Old 07-27-2008, 10:34 AM   #2 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 38
Default

Code:
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
this code displays "index.html" which is located in the project folder
marius
toom is offline   Reply With Quote
Old 09-10-2008, 05:09 PM   #3 (permalink)
ToM
InsiderApps.com
 
Join Date: Jul 2008
Posts: 101
Default

Thanks for that, helped me.
ToM is offline   Reply With Quote
Old 09-28-2008, 04:51 PM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 17
Default how can we make ALL the html local?

Lets say I have 10 pages of html that link to each other and I want to keep all those html files local. How can I use standard <a href> in the files to make sure that it uses the local files and not try to go to the web?
AwayBBL is offline   Reply With Quote
Old 09-29-2008, 09:25 AM   #5 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 211
Default

Use relative HREFS in all of your HTML pages. Donezo.
lapse is offline   Reply With Quote
Old 09-29-2008, 01:29 PM   #6 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 169
Default

But how do you get the html-file that is located locally to load a resource (image, sound, etc), also located locally? Ive tried putting both a .wav and .png file in the resources-folder where I have my html-file, but it only manages to load the actual html-file without the other resources...
Danneman is offline   Reply With Quote
Old 11-11-2008, 09:40 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 7
Default

Quote:
Originally Posted by lapse View Post
Use relative HREFS in all of your HTML pages. Donezo.
I try do relative HREFs , but UIWebView shows the blank page. (all pages registered in project)

Any advices - how to browse in local pages (for example, I have 3 local HTML pages), please?

Last edited by belgweb; 11-11-2008 at 09:57 PM.
belgweb is offline   Reply With Quote
Old 02-11-2009, 08:48 PM   #8 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

you can use

Code:
[WebView loadHTMLString:@"<img src=test.png>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
to display local resources
lbendlin is offline   Reply With Quote
Old 03-29-2009, 06:12 PM   #9 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by toom View Post
Code:
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
this code displays "index.html" which is located in the project folder
marius
Bump...

How would you modify this to serve pages from a subdirectory in the project?
jeffelkins is offline   Reply With Quote
Old 03-29-2009, 06:55 PM   #10 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

Ha funny. Read the documentation again. There are no subdirectories in projects.
lbendlin is offline   Reply With Quote
Old 03-29-2009, 07:04 PM   #11 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by lbendlin View Post
Ha funny. Read the documentation again. There are no subdirectories in projects.

Perhaps you misunderstood or I wasn't clear. I have two apps in the store right now that keep soundfiles in a sounds subdirectory. I just want to do the same for html files.

Given that "project" is the top level, any directories below "project" are what I'm talking about.
jeffelkins is offline   Reply With Quote
Old 03-29-2009, 07:51 PM   #12 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

Have you actually read the documentation? Doesn't matter how intricately you arrange your resources in Xcode. They all end up lumped together in the same folder on the device.

The Xcode directories/folders are just for your convenience during coding. They don't even need a physical equivalency on the Mac. So the sequence is "intricate folder structure on Mac"-"different intricate project structure in Xcode"-"dumb flat list on device".
lbendlin is offline   Reply With Quote
Old 03-29-2009, 07:55 PM   #13 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by lbendlin View Post
Have you actually read the documentation? Doesn't matter how intricately you arrange your resources in Xcode. They all end up lumped together in the same folder on the device.

The Xcode directories/folders are just for your convenience during coding. They don't even need a physical equivalency on the Mac. So the sequence is "intricate folder structure on Mac"-"different intricate project structure in Xcode"-"dumb flat list on device".
Thanks for your very polite explanation.
jeffelkins is offline   Reply With Quote
Old 03-29-2009, 07:58 PM   #14 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

sorry about that. I guess I am just angry about their design decision.
lbendlin is offline   Reply With Quote
Old 03-29-2009, 08:04 PM   #15 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by lbendlin View Post
sorry about that. I guess I am just angry about their design decision.
Funny...I just ssh'ed to my application's directory on my iTouch and guess what: there were actual directories with my sound files. They were NOT lumped into the root of the project.

So my original question is still unanswered.
jeffelkins is offline   Reply With Quote
Old 03-29-2009, 08:10 PM   #16 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

your original question was about HTML - why don't you try it out then, using an immediate redirect in your index.html file to a html file in a subfolder.

So you'd still call index.html, but would actually access a different file through a redirect (or a relative link on index.html)

I tried that too and it didn't work for me. Do your magic.
lbendlin is offline   Reply With Quote
Old 03-29-2009, 08:12 PM   #17 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Look at the NSBundle documentation. There are a bunch of methods for finding files and directories inside the bundle folder.
PhoneyDeveloper is offline   Reply With Quote
Old 03-29-2009, 09:48 PM   #18 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
Look at the NSBundle documentation. There are a bunch of methods for finding files and directories inside the bundle folder.
Thanks. Would that be bundleWithPath? If so, could you provide some guidance on how to use it?
jeffelkins is offline   Reply With Quote
Old 03-29-2009, 10:01 PM   #19 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by lbendlin View Post
your original question was about HTML - why don't you try it out then, using an immediate redirect in your index.html file to a html file in a subfolder.

So you'd still call index.html, but would actually access a different file through a redirect (or a relative link on index.html)

I tried that too and it didn't work for me. Do your magic.
Well, I have no magic or I wouldn't be posting. If I did, I'd snap my fingers and have a million dollars in my account for the ultimate fart app Thanks for your replies, though.
jeffelkins is offline   Reply With Quote
Old 03-29-2009, 11:19 PM   #20 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

I assume you meant bundlePath. [NSBundle mainBundle] is a singleton that refers to the main bundle of your app. On iPhone OS you can only have a single bundle but on MacOS its possible to have multiple bundles inside the main bundle and in fact you can load bundles from arbitrary paths. That's what bundleWithPath would do but it's obviously of no purpose on iPhone OS.

bundlePath, resourcePath and the related methods give you full paths to those directories. I'm not sure if the pathForResource methods will give you a path to a folder inside the bundle dir. They might. If they don't then you can build a path starting with mainBundle and using the methods in NSPathUtilities.h like stringByAppendingPathComponent.
PhoneyDeveloper is offline   Reply With Quote
Old 03-30-2009, 10:35 AM   #21 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 73
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
I assume you meant bundlePath. [NSBundle mainBundle] is a singleton that refers to the main bundle of your app. On iPhone OS you can only have a single bundle but on MacOS its possible to have multiple bundles inside the main bundle and in fact you can load bundles from arbitrary paths. That's what bundleWithPath would do but it's obviously of no purpose on iPhone OS.

bundlePath, resourcePath and the related methods give you full paths to those directories. I'm not sure if the pathForResource methods will give you a path to a folder inside the bundle dir. They might. If they don't then you can build a path starting with mainBundle and using the methods in NSPathUtilities.h like stringByAppendingPathComponent.
Thanks for your response.
jeffelkins is offline   Reply With Quote
Old 03-26-2010, 03:36 AM   #22 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default Did you ever get this to work?

Did you ever figure out how to do this? If so, I would very much like to know how you did it!

I'm trying to do pretty much the same task right now, but got stuck where you did. I posted a question similar to yours over at stackoverflow.
thomax is offline   Reply With Quote
Old 03-26-2010, 05:18 AM   #23 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Quote:
Originally Posted by thomax View Post
Did you ever figure out how to do this? If so, I would very much like to know how you did it!

I'm trying to do pretty much the same task right now, but got stuck where you did. I posted a question similar to yours over at stackoverflow.
I just solved this problem! Follow the link to stackoverflow if you are curious.
thomax is offline   Reply With Quote
Old 11-25-2010, 08:57 AM   #24 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Palo Alto, California
Posts: 8
Default How to load html files locally

Hi All,
I am novice on the ground of iphone application development.So my question is that i have made a presentation in html5 which includes different videos on different pages now i need to load these html files in my application locally.I am not able to access my html file locally imported in my project folder.My requirement is "how to load or call my local different html files(which are linked together)" into my project.

I have also used PhoneGap tool to achieve my target, but it does not help.

So please help me which would be highly appreciable.

Thanks.
imayank is offline   Reply With Quote
Old 01-20-2012, 05:31 AM   #25 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 1
Default opening more then one html at a time

Hey I just wanted to ask if there was a possibility of accessing more then one html at a time, in order to run a searching algorithm on many html files while still reading an html file. Currently I can run the search algorithm only on the opened html and I want to optimize the solution. If it is doable kindly give me hint of how to do it.
Thanks in advance
coder123 is offline   Reply With Quote
Reply

Bookmarks

Tags
local path, uiwebview, url

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 244
13 members and 231 guests
ADY, AragornSG, CKAmike, Dani77, Duncan C, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:19 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0