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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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-08-2011, 01:15 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default File location for iPod/iPhone/iPad

Hey all,

I am trying to write a file to somwhere on the device so that a javascript file can locate it. Current I am writing to the documents of the device. I am getting the directory but using
Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
But I have notice that to directory is different for iPod and iPad (i don't know about iPhone). I have tried writing to other folders along the directory path like
Code:
[responseString writeToFile:@"/var/mobile/test.json"
atomically:YES
encoding:NSUTF8StringEncoding
error:NULL];
But it doesn't seem to work. Is there somewhere that I can write the file that all the devices can access using the same directory.

Thanks
Clinton
Shades of Chaos is offline   Reply With Quote
Old 07-08-2011, 01:21 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

You can use the documents directory. You dont need to know the exact path i.e. the "/var/mobile...", just that you have the ability to write files there.

Why do you think you need to know the exact path, and moreover, why do you think this path needs to be the same on different devices?
smithdale87 is offline   Reply With Quote
Old 07-08-2011, 01:35 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default

Well I was using
Code:
[responseString writeToFile:[NSString stringWithFormat:@"%@/test.json", documentsDirectory] 
					 atomically:YES 
					   encoding:NSUTF8StringEncoding 
						  error:NULL];
And it wrote to the documents of the device just fine. But I am reading it from a javascript file. But when I used
Code:
NSLog(@"%@", documentsDirectory);
I noticed that it changed from the iPod to the iPad. So I think I need to either write the file using the same path or somehow pass documentDirectory into the javascript file.
Shades of Chaos is offline   Reply With Quote
Old 07-08-2011, 03:19 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Shades of Chaos View Post
Well I was using
Code:
[responseString writeToFile:[NSString stringWithFormat:@"%@/test.json", documentsDirectory] 
					 atomically:YES 
					   encoding:NSUTF8StringEncoding 
						  error:NULL];
And it wrote to the documents of the device just fine. But I am reading it from a javascript file. But when I used
Code:
NSLog(@"%@", documentsDirectory);
I noticed that it changed from the iPod to the iPad. So I think I need to either write the file using the same path or somehow pass documentDirectory into the javascript file.
There is no guarantee that the path to the documents directory will be the same between devices. In fact, it is likely to be different on every device. The system assigns a path to your app when it gets installed from the app store, and that path is quite likely to be different from device to device and user to user.

You should ask the system for the path to the documents directory and use that. Don't assume it will stay the same.

You will need a way to pass it to JavaScript of you need to use it in JavaScript.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 07-08-2011, 03:24 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default

How would I pass it to the javascript. I have a HTML file which I call and then the HTML file calls the javascript file. I am currently trying this
Code:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"RssiSample"];
	NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
	[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
	
	NSString* script = [NSString stringWithFormat:@"directory	= \"%@\";", documentsDirectory];
	[webView stringByEvaluatingJavaScriptFromString:script];
directory is a var located at the top of the javascript file. I believe it is a global var. But this code is not working. I think it is because I have not specified the javascript file but I am not sure how to do that.
Shades of Chaos is offline   Reply With Quote
Old 07-08-2011, 03:26 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Shades of Chaos View Post
How would I pass it to the javascript. I have a HTML file which I call and then the HTML file calls the javascript file. I am currently trying this
Code:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"RssiSample"];
	NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
	[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
	
	NSString* script = [NSString stringWithFormat:@"directory	= \"%@\";", documentsDirectory];
	[webView stringByEvaluatingJavaScriptFromString:script];
directory is a var located at the top of the javascript file. I believe it is a global var. But this code is not working. I think it is because I have not specified the javascript file but I am not sure how to do that.
I have no idea. I know very little about JavaScript. Sorry.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
directory, documents, file, json, location

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: 357
9 members and 348 guests
apatsufas, chemistry, lendo, leostc, Leslie80, lzwasyc, MarkC, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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