Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 11-26-2008, 01:45 PM   #1 (permalink)
Registered Member
 
Join Date: May 2008
Location: New York City, NY
Posts: 177
Default printing the path to a file

Hi,

I've got a local html file I'm displaying in a UIWebView. I set that up like:
Code:
    [m_webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"]isDirectory:NO]]];
Now inside test.html, I want to import a javascript file which is also just in my main project directory, I tried this inside the html:

Code:
<script type="text/javascript" charset="utf-8" src="test.js"></script>
but that does not work, I guess I have to give it the absolute path to the javascript file. I tried doing this to figure it out:

Code:
NSString* info = [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"js"]isDirectory:NO] absoluteString];
NSLog(info);
but I get some wild characters printed out to the console. How do you print out the absolute path correctly?

Thanks
markww is offline   Reply With Quote
Old 11-26-2008, 02:07 PM   #2 (permalink)
Registered Member
 
Join Date: May 2008
Location: New York City, NY
Posts: 177
Default

Ok so it seems this is the correct way to print the path:

Code:
NSString* info = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
so that will give me the path which is excellent, but when I try that for my "test.js" file, it just prints an empty string, so I'm assuming that means my js file cannot be found.

Now I notice when building my project, I get this warning about the js file:

warning: no rule to process file '$(PROJECT_DIR)/test.js' of type text for architecture i386

so is the simulator considering the js file as not present? How can I resolve that warning? I get it if I change the extension to .txt as well. Doesn't appear for .html files though.

Thankyou
markww is offline   Reply With Quote
Old 11-26-2008, 02:42 PM   #3 (permalink)
Registered Member
 
Join Date: May 2008
Location: New York City, NY
Posts: 177
Default

Alright so I see XCode was trying to add the javascript file to the compiled sources folder. Deleted it from there, and moved it into the Copy Bundle Resources folder.

Now it appears with at the same location as my html file, I'm printing the paths and get:

Code:
2008-11-26 15:36:47.885 myapp[2729:20b] /Users/mark/Library/Application Support/iPhone Simulator/User/Applications/1CC029F4-AF6B-4E19-91BR-66DA276F83B5/myapp.app/test.html
2008-11-26 15:36:47.890 myapp[2729:20b] /Users/mark/Library/Application Support/iPhone Simulator/User/Applications/1CC029F4-AF6B-4E19-91BR-66DA276F83B5/myapp.app/test.js
But referencing it in that html file still fails, again, doing:

src="test.js"

but no luck.
markww is offline   Reply With Quote
Old 11-26-2008, 09:52 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

I think that one of the webview methods for loading files allows you to set the base dir. You need to set that in order for relative paths to work in an html file.
PhoneyDeveloper is offline   Reply With Quote
Reply

Bookmarks

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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 228
21 members and 207 guests
churn, ddorrity, donbhar, Ed99, funhog, gardenofwine, hobbyist, inetryconydot, jj0b, linkmx, masc2279, mriphoneman, pereorra, ravi124, redmouse, scotopia, smilespray, smrtital, ybrikeeg, zackattack, _nivek
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,276
Threads: 39,069
Posts: 171,323
Top Poster: smasher (2,575)
Welcome to our newest member, jstewuk
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0