Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

get path to <Application_Home>/Library/Caches on iOS

Hi,

since the iOS data storage guidelines indicate that all data that can be regenerated should be stored in <Application_Home>/Library/Caches, what is the Titanium way to recieve that path reliable for all iOS versions?
in Titanium.API.Filesystem I could not find a related constant.

— asked October 7th 2011 by Max Stricker
  • cache
  • filesystem
  • folder
  • ios
2 Comments
  • Can you give us a little more detail? What type of app are building? What Titanium SDK are you using? Do you have a direct link to the guideline you are mentioning?

    — commented October 7th 2011 by Tony Lukasavage
  • i referred to this document. I am using Titanium Developer 1.2.2
    Any other information needed?

    — commented October 7th 2011 by Max Stricker

15 Answers

  • While waiting for a solution…

    exports.cacheDirectory = 
    Titanium.Filesystem.applicationDataDirectory + "../Library/Caches/";
    

    This works on simulator and device and isn't rocket science :)
    This is what where using for now. (we have an app submitted, not approved yet)

    — answered November 29th 2011 by Gertjan Smits
    permalink
    11 Comments
    • Yes that is what we are doing too for now, however your app data is at risk and can be deleted at any time. Let me know if your app is accepted with this approach since that is the only workaround we have found.

      — commented November 29th 2011 by Isaac Sunkes
    • Thanks for the tips !

      This report seems to be resolve in 1.8.1 ? http://jira.appcelerator.org/browse/TIMOB-6273

      — commented November 29th 2011 by Greg Carlin
    • From the ticket:

      Status: Open

      Priority: Medium

      Resolution: Unresolved

      Affects Version/s: Release 1.7.5, Release 1.8.0, Release 1.8.0.1

      Fix Version/s: None

      — commented November 29th 2011 by Isaac Sunkes
    • When approved please write a short notice here. Thanks.

      — commented November 29th 2011 by Torsten Stelling
    • Will do.

      — commented November 29th 2011 by Gertjan Smits
    • Any news about your validation Gertjan?
      We submitted an app one week ago and has been rejected yesterday, we re uploaded a new version with database and images stored in Library/Caches BUT we still have folders created automatically : Library/Preferences (created when we used Ti.App.Properties.setString) and Library/Cookies (created when we open a Webview).

      — commented November 30th 2011 by Yvic Pineau
    • Nothing yet. We submitted last friday.

      — commented November 30th 2011 by Gertjan Smits
    • This ticket is now resolved, the fix is in the 1.8.0.1.v20111129200258 build.

      A couple of questions:

      1) Is look like it is sufficient to set just the folder's remoteBackup flag to exclude all files in the folder:

      // set the application data directory
          PTC.dataDirectoryName = "PrivateAppData";
          PTC.applicationDataDirectory = Ti.Filesystem.applicationDataDirectory.replace("Documents","Library/" + PTC.dataDirectoryName);
      
          // check to see if the directory exists
          var dataDir = Titanium.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory.replace("Documents","Library"), PTC.dataDirectoryName);
          if( !dataDir.exists()){
            dataDir.createDirectory();
      
            // set the Do Not Backup Flag
            dataDir.remoteBackup = false;
          }
      

      I then reference my app's data directory instead of the titanium default.

      2) The Documents/Preferences folder seems to be getting backed up but I don't know if Apple's guidelines allow it.

      3) Same for the app log file in the root of the Documents folder; does this need the remoteBackup flag too?

      Thanks again for all your help,

      Brian Caufield

      — commented November 30th 2011 by Isaac Sunkes
    • Hi,

      I have difficulties to understand the process.

      My app use local data, not remote. Actually in my Titanium project, all data (images + database is located in Resources/images/myImages).

      Does i have to move manually this folder in another directory or just set the "do not back up" flag ?

      — commented December 5th 2011 by Greg Carlin
    • Read only data that is installed with your app is fine, this issue is with data that is downloaded by the app based on the user's request. Before iOS 5.0, you could safely store this data in the app's Documents folder. That is no longer the case and you now must store app data in a folder that has the "remoteBackup" flag set to false.

      — commented December 5th 2011 by Brian Caufield
    • Ok, Thanks Brian.

      The problem is Apple rejected my app while i've only local data, no downloading. So no flag on my Resources/images/myImages ?

      Thanks for your help :)

      — commented December 5th 2011 by Greg Carlin
  • This seems not to give the right path. I do:

    var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename);
    f.write(this.responseData);
    

    Using the iPhone Simulator the fle is placed in
    Library&#x2F;Application Support&#x2F;iPhone Simulator&#x2F;4.3.2&#x2F;Applications&#x2F;XXXAPPID&#x2F;Documents&#x2F;
    but it should be in
    Library&#x2F;Application Support&#x2F;iPhone Simulator&#x2F;4.3.2&#x2F;Applications&#x2F;XXXAPPID&#x2F;Library&#x2F;Caches

    — answered October 8th 2011 by Max Stricker
    permalink
    0 Comments
  • Ok guys, you must use version 1.7.3 or greater of the mobile sdk to use iOS5.

    — answered October 18th 2011 by Anthony Decena
    permalink
    0 Comments
  • We're having the same issue here, our app just got rejected for this reason. Any help would be appreciated :)

    — answered November 22nd 2011 by Gertjan Smits
    permalink
    0 Comments
  • It seems like there is a new flag in Ti.Filesystem.File called remoteBackup. Simply set that always to false and your files are still in the documents directory but not backed up via iCloud.
    BUT: Note that this actually prevents ALL backups, not just to iCloud.

    — answered January 28th 2012 by Christopher Heymann
    permalink
    0 Comments
  • The constant applicationDataDirectory within the Filesystem API automatically targets this location for you. You can target a file within that directly like so:

    Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'file.txt');
    
    — answered October 8th 2011 by Anthony Decena
    permalink
    0 Comments
  • Same problem. I have a large read only database in my app that I install the db with Titanium.Database.install. Titanium placed the database in:

    Library&#x2F;Application Support&#x2F;database

    Since iOS 5 and iCloud integration the database should be placed in:

    Library&#x2F;Caches

    I got an email from Apple that I have to change this in my app but I can't set the path where Titanium installs the database.

    Any ideas?

    — answered October 12th 2011 by Mario Müller
    permalink
    2 Comments
    • My problem is the same , only that I don't want to install the database in that folder but put some downloadable content there. Also I have received an email form an Apple developer that I need to update my App to be compliant with their rules for iOS 5. And since it has been released already I need to urgently update.

      @Appcelerator: any updates on the situation? Since all Apps for iOS 5 have to store large content that can be regenerated in the Cache folder in order to exclude it from iCloud as far as I understand there needs to be a way to access that path in Titanium.

      — commented October 13th 2011 by Max Stricker
    • Do you resolve that problem ?

      Thanks

      — commented December 6th 2011 by Greg Carlin
  • This seems to one of the only threads that is trying to deal with the problems caused by iOS 5 and iCloud updates. My app was just rejected from the app store due to violating these new data storage policies; I have been able to move all the downloaded data and databases to the Caches folder as described above but now I risk having all this data deleted if the device is low in storage space. Apple says that we should create a new private folder and set the "do not back up" attribute (http://developer.apple.com/library/ios/#qa/qa1719/_index.html). Has anyone figured out how to do this via Titanium?

    — answered November 18th 2011 by Isaac Sunkes
    permalink
    0 Comments
  • There is a Jira issue for this problem located here:
    http://jira.appcelerator.org/browse/TIMOB-6273
    Let's hope they come up with a work around.

    — answered November 22nd 2011 by Isaac Sunkes
    permalink
    0 Comments
  • I also have this problem , my app has been rejected for the same reasons..

    All my apps are concerned. This is really a big problem.

    Hope a workaround rapidly.

    Thanks.

    — answered November 29th 2011 by Greg Carlin
    permalink
    0 Comments
  • According to the JIRA issue TIMOB-6286, they think this is a trivial issue; I argued the priority up to "medium" but they still have it scheduled for the 1.9.0 release. Please add a comment to this issue complaining about this; I can't believe they don't see how big a big problem this is.

    — answered November 29th 2011 by Isaac Sunkes
    permalink
    0 Comments
  • According to the JIRA issue TIMOB-6286, they think this is a trivial issue; I argued the priority up to "medium" but they still have it scheduled for the 1.9.0 release. Please add a comment to this issue complaining about this; I can't believe they don't see how big a big problem this is.

    — answered November 29th 2011 by Isaac Sunkes
    permalink
    0 Comments
  • We also need the cache folder for our upcoming release. Apple will not approve it currently, since we put all cached data in the documents folder.

    — answered November 29th 2011 by Torsten Stelling
    permalink
    0 Comments
  • Our app got approved! All in Titanium.Filesystem.applicationDataDirectory + "../Library/Caches/";

    — answered December 5th 2011 by Gertjan Smits
    permalink
    0 Comments
  • Is data safe in this location Titanium.Filesystem.applicationDataDirectory + "../Library/Caches/" for say 100s of MB of information? Is there a risk of that data being deleted automatically in some form of cache purge?

    — answered April 11th 2012 by P Sweeney
    permalink
    5 Comments
    • In an iOS app the only time the cache would be purged would be if you deleted the app. In which case you would want all app related data purged.

      I had to start using this directory after Apple rejected updates to several gallery iPad apps, which download large numbers of full screen images and cache locally. When the iCloud was introduced, the application data directory was targeted for backup, and Apple introduced limits on what could be stored there.

      — commented April 11th 2012 by Julian Fraser
    • Hi Julian, thanks for your prompt response. That sounds hopeful so, as I was hoping that would be the case - the use of the safety in 'cache' has to be taken with great hesitation, because if you're relying on a file to be there and it's not, then there's a problem :)

      If the cache is controlled by the app/developer, then we're away laughing - I had Apple call me yesterday telling me I was uploading 9mb to iCloud, even though the app is configured on the iOS Developer Center to not use iCloud. It's still unticked/unconfigured technically, so why is it happening? Any thoughts?

      — commented April 11th 2012 by P Sweeney
    • It may just be a case of Apple making attempts to enforce their will on the world as usual. We had the same issue. Our apps were not using the iCloud, in fact the update went in only a couple of days after iCloud went live.

      I think it's just a red flag that pops up when they review the app, because when iCloud is actually configured, the application data directory is backed up.

      — commented April 11th 2012 by Julian Fraser
    • They're just… argh.. so annoying. Police state or what. So what if it's being backed up, it's the user's content technically - they fetched it.

      — commented April 11th 2012 by P Sweeney
    • In relation to:

      The Library Directory Stores App-Specific Files

      and

      iOS Standard Directories: Where Files Reside

      They seem to regard the Caches folder as not being sacredly safe (in terms of when iOS is low on space, the cache folders can/will be purged to allow for optimisation of storage usage).

      The conundrum I'm facing is that I cannot use any version higher than Titanium 1.7.5 because for some reason my createHTTPClient(); won't fire the .onload() function when in any version higher/other than 1.7.5, even when I fully delete the build folder contents to build from fresh.

      Does anybody have a solution to this issue - I cannot update to the Titanium version high enough to allow myself to set the file.remoteBackup = false so that I can store files in the /Documents folder instead (which would answer all our problems!), so instead, the only alternative I have is the /Cache folder which seemingly is not a fully reliable solution.

      Any suggestions to fixing the above issue? I've tried almost all the solutions mentioned in the Q&As regarding this prob but still no joy :( It won't download my files for me.

      Wisdom is MOST welcomed on this one as it's a fairly big stumbling block.

      — commented April 11th 2012 by P Sweeney
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.