Open Source & Free  

Storage Migration

Storage Migration

Header Image

Our iOS port has some pieces that are pretty old and haven’t been touched since we started, one of those things
is the IO code which mostly works as we wrote it when we started Codename One. Unfortunately it seems that
Storage in iOS is mapped to the iOS caches directory, this directory can be wiped by the iOS device if space
on the device is running low. That’s a very rare occurrence which is why we didn’t pick that up until a
bug report was filed on it this week

Unfortunately fixing Storage to point at the right directory would mean breaking compatibility and your app
losing all the data it kept in storage… So we decided to go about this in a rather creative way.
We defined a new build argument which will be on by default for all new projects: ios.newStorageLocation

This build argument effectively means that we should use the documents directory as storage and the app is ready
to deal with it. Its useful for apps that aren’t already in users hands. If you don’t define that flag we will automatically
migrate the app to the documents directory on the first usage of Storage, we will detect if our
storage directory exists under documents and if not we will move all files to that directory. This should maintain
compatibility with a small performance overhead on the first activation for new installs and possibly the first
time this code occurs in a pre-existing app.

5 Comments

  • Maaike Z says:

    Is it a boolean? So ios.newStorageLocation = true when I want to use the new location?

  • Shai Almog says:

    Yes it should be true/false (notice its not yet on the servers and will be there before the weekend).
    We already documented it in the manual section: [http://www.codenameone.com/…](http://www.codenameone.com/manual/advanced-topics.html#_sending_arguments_to_the_build_server)

  • kazza186 says:

    Has there been a change with this? I’ve just found this because I’m having the exact problem where data is being wiped on iPhones with low storage space, but I never defined this hint so shouldn’t it be using Documents directory? My files are being stored in Library/caches when I use the codename one file storage. Is that correct? How do I switch it to use the Documents? Thanks.

  • Shai Almog says:

    No. The build hint should be defined there by default. Which IDE are you using?
    When did you create the project and which project type did you select?
    Check the FileSystemStorage.getRoots values on the device. Print them to a dialog or log. They should be arranged as documents first and caches second. If not then the build hint isn’t turned on for some reason.

  • kazza186 says:

    Printed it to a Dialog without the build hint added. Cache was first, then Documents. Have added the build hint now and it’s using Documents instad of Cache which is good.
    I’m using Eclipse, created the project in January 2016. I can’t remember which project type I used sorry.

Leave a Reply