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 01-11-2009, 09:35 AM   #1 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default How do I clear my temp directory in the simulator?

I've started caching graphics that my app downloads off the net to my app's temp directory using NSTemporaryDirectory().

I need to be able to scrub my temp directory clean to test initialization.

However, nothing I do clears out the temp directory. I can delete my app from the simulator's springboard; I can use the "reset content and settings" command, I can stand on my head, but the files in temp remain. What's going on here?

Also, when I go and look in ~Library/Application Support/iPhone Simulator/User/Applications, I can see my app's directory, including it's temp directory. However, the tmp directory appears empty. What's up with that? Are the files tagged as invisible?

I don't remember how to specify paths that include spaces in terminal, so I can't look in tmp there.

Help!


Duncan
Duncan C is offline   Reply With Quote
Old 01-11-2009, 10:40 AM   #2 (permalink)
Registered Member
 
tkilmer's Avatar
 
Join Date: May 2008
Posts: 583
Default

For spaces in the terminal, surround with "".

cd Desktop/"My Folder"/images
tkilmer is offline   Reply With Quote
Old 01-11-2009, 11:44 AM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default Using Mac OS paths in terminal, handling spaces

Quote:
Originally Posted by tkilmer View Post
For spaces in the terminal, surround with "".

cd Desktop/"My Folder"/images
I found a reference that helped me with this.

I can also escape spaces and other single special characters with a backslash, so your example would be


cd Desktop/My\ Folder/images

Another REALLY cool trick is that you can type a command, then drag a file or folder onto the command line in terminal. The terminal app will put the path to that file folder right in-line. Very helpful.

Last edited by Duncan C; 01-11-2009 at 11:44 AM. Reason: typo
Duncan C is offline   Reply With Quote
Old 01-11-2009, 12:51 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default Progress, more questions

I found my app's tmp directory on the simulator. To find it, I used to locate command. To use locate, I first had to build a locate database for my Mac. To do THAT, I issued the following command in the terminal:

sudo /usr/libexec/locate.updatedb

Be aware that that command builds a locate database that any user on your Mac can use to see any file, even files that are normally not accessible to other users.

Once you've done that, you can use the locate command to locate a file that you know should be in your tmp directory. My app created a file I new should be there, so I used that filename.

The result I got was the following path:

/private/var/folders/f7/f7MhxBVPFt4q1lU9r0pfjU+++TI/-Tmp-/

The "f7MhxBVPFt4q1lU9r0pfjU+++TI" part of that path is, I think, an encoded version of the UUID (unique ID) for the application.


Does anybody know if I would cause any problems in the simulator if I used the terminal to delete all the files in that temp directory? There are a few files that I did not create, like: xcodeDocAccess.

Thanks for any help
Duncan C is offline   Reply With Quote
Old 01-11-2009, 01:27 PM   #5 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

I have some code that deletes everything in the app temp folder. It causes problems if I run it on the simulator. On the sim the temp folder is shared among other apps and deleting some Xcode files that are in there did cause some problems with Xcode, although not extremely bad problems.

I run the temp folder deleting code only on the device. I don't delete the folder itself, only the contents.

What you could do is make sure to add a folder inside the temp folder with a unique name and only put your temp files inside that. Then delete this folder only when you need to.
PhoneyDeveloper is offline   Reply With Quote
Old 05-15-2009, 11:36 AM   #6 (permalink)
New Member
 
Join Date: May 2009
Posts: 3
Default Temp directory

On a similar note, how do I clear the temp directory on the device?
I have a UIwebView leak. The only way to stop the crashing seems to be to reboot the iPhone.
I don't understand the difference that happens when the iPhone is rebooted vs. have the program quit.

Is there a way to clear ALL the cache? I've tried setting
[[NSURLCache sharedURLCache] setMemoryCapacity: 0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
and
NSURLCache *sharedCache = [NSURLCache sharedURLCache];
[sharedCache removeAllCachedResponses];

What does a reboot do that I can't seem too?
Glibnobin is offline   Reply With Quote
Old 05-18-2009, 10:50 PM   #7 (permalink)
New Member
 
Join Date: May 2009
Posts: 3
Default

hi Phoney, What's that code that clears the temp folder on the device.
Glibnobin is offline   Reply With Quote
Old 03-16-2010, 04:10 PM   #8 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 160
Default

Quote:
Originally Posted by Glibnobin View Post
hi Phoney, What's that code that clears the temp folder on the device.
Did anybody ever figure out when the temp directory clears on the device? Will a reboot clear the temp directory?
Vortec4800 is offline   Reply With Quote
Old 03-16-2010, 04:45 PM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default restart clears the temp directory

Quote:
Originally Posted by Vortec4800 View Post
Did anybody ever figure out when the temp directory clears on the device? Will a reboot clear the temp directory?
Yes, a restart clears the temp directory.
Duncan C is offline   Reply With Quote
Old 07-03-2010, 02:51 PM   #10 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 2
Default

You can get the tmp directory name on your mac by using this in your code:

Code:
- (void)cacheDirectory {
	
	NSString *tempPath = NSTemporaryDirectory();
	
	NSLog(@"Temp Value = %@", items);
}
Call the method from wherever you want.

This will return the tmp folder name, then in finder do (cmd-shift-G) and paste the response you got from the console window.

Last edited by bordashell; 07-04-2010 at 06:30 AM.
bordashell is offline   Reply With Quote
Old 07-04-2010, 06:29 AM   #11 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 2
Default

The following will clear the TMP directory used by the Simulator.

Code:
NSString *tempPath = NSTemporaryDirectory();
NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:tempPath];
NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"]];

NSFileManager *fileManager = [NSFileManager defaultManager];

if (onlyJPGs) {	
	for (int i = 0; i < [onlyJPGs count]; i++) {
	NSLog(@"Directory Count: %i", [onlyJPGs count]);
	NSString *contentsOnly = [NSString stringWithFormat:@"%@%@", tempPath, [onlyJPGs objectAtIndex:i]];
	[fileManager removeItemAtPath:contentsOnly error:nil];
}
The above code clears only JPGs from the directory, so if you want to clear anything else then amend it.
bordashell is offline   Reply With Quote
Reply

Bookmarks

Tags
clearing, simulator, temp, tmp

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: 249
22 members and 227 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, dacapo, Dani77, DarkAn, Davey555, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, ryantcb, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,766
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 02:44 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0