HOWTO: Cleaning the App's tmp folder (NOT documents/tmp) ?

594 views
Skip to first unread message

Jan Gregor Triebel

unread,
Jul 27, 2011, 1:34:04 PM7/27/11
to phon...@googlegroups.com
Hey everybody :-)

So I am coding an App that (among other features) lets users upload a picture (which is taken from inside the App - Or is there a way to get them from the Camera Roll ??? ). Anyways ... So when the user takes a pictures it is saved in the App's tmp folder.

After I have used this feature a lot for debugging, I noticed that the tmp folder got pretty crowded. So I began to ask myself when and how it is cleaned up. It is not cleaned up, when the App closes, nor when the device restarts. Do I need to trigger this manually and if so: how ?? Or will the system (in my case iOS) just do that at some random point ?

I am really looking for some clues here ....
(PS: feel free to talk about the Camera Roll issue as well ;-) )

Phil

unread,
Jul 27, 2011, 1:42:19 PM7/27/11
to phonegap

Jan Gregor Triebel

unread,
Jul 27, 2011, 1:44:00 PM7/27/11
to phon...@googlegroups.com
I figured that out as well ... just that I do not code Objective-C. I only use phonegap(JS/CSS ...) - so what am I supposed to do ?

Phil

unread,
Jul 27, 2011, 1:55:06 PM7/27/11
to phonegap
Have you tried FileEntry remove method?

http://docs.phonegap.com/

I don't know how that interfaces with an iOS app's subdirectories.
Normally you would use the NSTemporaryDirectory function to get the
complete path to tmp within the app's home folder.

Thanks.

-Phil

Jan Gregor Triebel

unread,
Aug 4, 2011, 11:15:49 AM8/4/11
to phon...@googlegroups.com
That function only reaches as far as your root directory (which is /documents/) . However, the tmp folder I am talking about is the one at the first level of the app's filesystem, this level cannot be reached with phonegap's API. So how can I clean this directory ?

Phil

unread,
Aug 4, 2011, 12:12:11 PM8/4/11
to phonegap
tmp is at same level as Documents under the app's home directory:

http://web.me.com/macpgmr/ObjP/Xcode4/ObjP_Part5.html#The%20Sandbox

Thanks.

-Phil

Jan Gregor Triebel

unread,
Aug 4, 2011, 2:03:55 PM8/4/11
to phon...@googlegroups.com
I know :-)

But I cannot get the filehandler to access that directory. Do you have any idea where I can find a good tutorial on the issue other than phonegap's documentation ... which I do not completely understand (sorry I'm German :-( )

Phil

unread,
Aug 4, 2011, 2:09:20 PM8/4/11
to phonegap
The API doc does seem kind of skimpy on examples that one might
actually use.

A couple of things come to mind:

- Don't forget that iOS file system is case sensitive, so it's
"Documents", not "documents", etc.

- How are you determining the path to "tmp"?

Thanks.

-Phil

Jan Gregor Triebel

unread,
Aug 4, 2011, 2:20:40 PM8/4/11
to phon...@googlegroups.com
I thought I could use this - but it doesn't work ... How am I supposed to do it ?

entry.getDirectory("tmp", {create: false, exclusive: false}, success, fail);

Phil

unread,
Aug 4, 2011, 2:24:19 PM8/4/11
to phonegap
I haven't used the JS API on PhoneGap, but I guess one question would
be what "tmp" is relative to. If it's relative to the executable,
remember that it's in the app bundle, one level down from where tmp is
(that is, the app bundle, tmp and Documents are at the same level).

What if you assumed that getDirectory is relative to the executable,
and used "../tmp" ?

Thanks.

-Phil

Simon MacDonald

unread,
Aug 4, 2011, 2:24:59 PM8/4/11
to phon...@googlegroups.com
Call -

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onSuccess, onError);

and the onSuccess() method will be called with a FileSystem object.
From the FileSystem object you can access the root property which is
of type DirectoryEntry. In this case that should by your apps
temporary directory.

Simon Mac Donald
http://hi.im/simonmacdonald

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Jan Gregor Triebel

unread,
Aug 5, 2011, 3:04:10 PM8/5/11
to phon...@googlegroups.com
Thanks a million - that was really what I needed :-) 
What I am now doing to read the tmp dir is this (just in case anybody faces the same problem):


function success(entries) {

    var i;

    for (i=0; i<entries.length; i++) {

        console.log(entries[i].name);

    }

}


function fail(error) {

    alert("Failed to list directory contents: " + error.code);

}



function onFileSystemTemporarySuccess(fileSystem) {

    console.log(fileSystem.root.name);

    

    // Get the directory

    var directory = fileSystem.root;

    

    // Get a directory reader

    var directoryReader = directory.createReader();

    

    // Get a list of all the entries in the directory

    directoryReader.readEntries(success,fail);

    

}


function failedFileSystem(evt) {

    console.log(evt.target.error.code);

}



function getFileSystem() {    

    window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemTemporarySuccess, failedFileSystem);

}

Phil

unread,
Aug 5, 2011, 3:20:47 PM8/5/11
to phonegap
That should probably go in the wiki somewhere so it doesn't get lost.

Thanks.

-Phil
Reply all
Reply to author
Forward
0 new messages