API Development

Changes to filesystem on iOS

With the release of Titanium 1.7.0, there have been some changes put in place on iOS to help with relative and absolute path resolution for files on the device, and to allow better cross-platform development by interpreting paths and providing directory information the same way that Titanium on Android does.

Previously, file operations on iOS were performed only on paths, which were used interchangeably with file URIs. There was always some confusion about where exactly a “relative” path was relative to, and whether absolute paths should be measured from the root of the filesystem (which developers generally do not have access to) or from some other location that makes more sense for your application. Now, there are some consistent guidelines for filesystem use on iOS:

  • Relative paths are now considered to be relative to the javascript file they are being executed from.
  • Absolute paths are now considered to be relative to the application resources directory (i.e. the same directory where your app.js is stored).
  • All other paths – including those returned by Titanium.Filesystem properties – are now file URIs. For example, Titanium.Filesystem.resourcesDirectory it is now a file URI pointing to the resources directory of the application (where the app.js is stored) – including a trailing slash.

Will log what you’d hope it would (‘X is: Hello!’) to the console.

For those of you writing custom modules that take advantage of the filesystem, to conform to these new guidelines, you will need to make sure that you handle paths in a manner consistent with Titanium. We provide two internal methods in our source which you can use for this: +[TiUtils toURL:proxy:] and +[TiUtiuls toURL:relativeToURL:]. These translate string paths to NSURL objects, which can then have their filesystem path component extracted.