When is system.TemporaryDirectory cleared ?

I don’t usually like to mess around with this stuff LOL - yet.

Like you said - it’s with the Xcode simulator only, and I don’t think it will be an issue that causes a crash or hang up on the app on the device. At least so far I haven’t seen it be an issue in testing on my device. I just don’t like any warnings or errors to be unaddressed before I build an app. I don’t know in a tutorial once, somewhere, I heard not to ignore warnings and errors.  :wink:

Cheers!

Warnings are usually there for a reason  :slight_smile:

Another safer way to delete an app in the Xcode simulator is one-at-a-time. The same you you would on an actual device.

Just press-and-hold an app-icon and wait for it to start to jiggle. Then press the (X).

I assume you just need to delete the app you’re working on. Once done, re-install and see if you still get the error.

Yeah I use the jiggle to delete one at a time. Safer is best for me right now - still learning - and there’s nothing more frustrating then when you get unexpected behaviour. Especially when it takes me sometimes days, sometimes weeks, to figure out what the problem was. Only, to find out it was something small and overlooked. But what better way to learn - “won’t be doing THAT again!”

@ingemar

Cheers, deleted the app, reset Xcode sim and no error any more!

Thanks for all the help.

Hi thanks for this info, very helpful.

I am having an issue with the image (that was downloaded) staying the same, even after changing the image file on the server.

In other words, if image1.png was downloaded once and then the next day image1.png was changed on the server ( same name but different image ), the app still shows the old image1.png instead of re-downloading it (??) and displaying the new image1.png? Am I mis-understanding how the network.request call works? Shouldn’t it download the image1.png every time it is called?

I clear the temp directory of image1.png right before the network.request() call for the download so I don’t understand why the app still shows the “old” version of image1.png and not the new version of image1.png from the server / download.

Any help would be appreciated.

Cheers!

here is the code I am using:

local function clearTempDir()

                local lfs = require “lfs”

                local doc_path = system.pathForFile( “”, system.TemporaryDirectory )

                local destDir = system.TemporaryDirectory  – where the file is stored

    

                    for file in lfs.dir(doc_path) do

                        – file is the current file or directory name

                        os.remove( system.pathForFile( file, destDir  ) )

                        print("Temp Dir Cleared, removed file: ", file)

                    end

            end    

clearTempDir() – to remove former versions of the images that were downloaded before

                    local params = {}

                            params.progress = true

                    network.download(

                            “http://www.myServer.com/image1.png”,

                            “GET”,

                            image1Handler,

                            params,

                            “image1.png”,

                            system.TemporaryDirectory

                            )

                    

Actually - I read this post / tutorial here:

http://coronalabs.com/blog/2013/03/19/updating-mobile-game-content-in-runtime-guest-post/

Sounds good, also downloading to a custom directory is found here:

http://forums.coronalabs.com/topic/34057-downloading-to-a-custom-directory/

Both excellent resources on this topic, however - my image1.png is still not displaying the new version from the server after being changed.

I will experiment with the XML update process described in the first link I posted in the post. Maybe that will make a difference.

Cheers!

@Appsessed

Your old image is probably being cached by a proxy server.

Try adding:

params.headers={["Cache-Control"] = "max-age=86400, must-revalidate"}

max-age is the maximum age (in seconds) that a cached file can have before being reloaded by the proxy server.

86400 = 1 day (60 seconds * 60 minutes * 24 hours)

After changing this, you might need to run your app twice. The first time it will update the proxy with the new header.

@ingemar

Thanks this fixed the image replacement problem, however (of course) there is now a new error msg coming up when I run the app in the simulator as follows:

ERROR: unable to get the receiver data from the DB!

This pops up whenever it is loading the next image in the que from the server. It does’t happen every time, seems to only happen on first launch.

Is this something I should be concerned about? What does this mean exactly? These images have nothing to do with our DataBase  AND there are no DataBase calls in between the network.download requests for the image assets however this error pops up.

Hmm…

I’m new to all of this, by the way :smiley: , so thanks for all of the help.

Cheers!

Corona sdk caches images based on filename.  Once an app loads image1.png (jpg), the system never gets another copy from the device, even if it is deleted, and re-downloaded.  The only way I know of to have images with the same name work as expected – is they must be in different folders  (the system uses the full pathname as well to determine if it is already cached).

The only solution I know of is to save the file locally with a different name (or keep updating the server names).  You can check the forums, but I believe this is the case still (and intentionally - for high perfomance gaming/caching).

Thanks mpappas. I will do some more research on that. Still wondering what that error message means though.

Cheers!

Corona sdk caches images based on filename.  Once an app loads image1.png (jpg), the system never gets another copy from the device, even if it is deleted, and re-downloaded. 

Appsessed is talking about a different issue.

The Corona caching only occurs while the app is running. As you pointed out, an image is cached when it’s first used and any subsequent calls to newImage() or the like will get the cached image regardless of if it’s been changed or not.

If you remove the app from the background (and make sure your app’s cache is cleared), the images will be re-downloaded again on “first launch”. If a proxy is caching you’ll get the old images, but adding the header I posted above to network.download() fixes that issue.

@Appsessed

You’re talking about the Xcode simulator, right? I don’t think you need to be worried. It’s usually the Simulator cache that’s acting up.

You can try to delete all apps from the simulator with the following command:

(replace “replace-with-your-simulator-version” with the version of the simulator you’re simulating.

rm -rf ~/Library/Application Support/iPhone Simulator/replace-with-your-simulator-version/Applications/\*

CAUTION! As always with the rm -rf command: Be _ extra _ careful that you’ve typed the correct folder location or you might mess things up badly.

@ingemar

Yes the header statement you suggested is working for the behaviour I was looking for, I can now change the image on the server and upon relaunch the new image is loaded - after the max-age stated in the header.

Cheers!

I don’t usually like to mess around with this stuff LOL - yet.

Like you said - it’s with the Xcode simulator only, and I don’t think it will be an issue that causes a crash or hang up on the app on the device. At least so far I haven’t seen it be an issue in testing on my device. I just don’t like any warnings or errors to be unaddressed before I build an app. I don’t know in a tutorial once, somewhere, I heard not to ignore warnings and errors.  :wink:

Cheers!

Warnings are usually there for a reason  :slight_smile:

Another safer way to delete an app in the Xcode simulator is one-at-a-time. The same you you would on an actual device.

Just press-and-hold an app-icon and wait for it to start to jiggle. Then press the (X).

I assume you just need to delete the app you’re working on. Once done, re-install and see if you still get the error.

Yeah I use the jiggle to delete one at a time. Safer is best for me right now - still learning - and there’s nothing more frustrating then when you get unexpected behaviour. Especially when it takes me sometimes days, sometimes weeks, to figure out what the problem was. Only, to find out it was something small and overlooked. But what better way to learn - “won’t be doing THAT again!”

@ingemar

Cheers, deleted the app, reset Xcode sim and no error any more!

Thanks for all the help.