Copy files to Documents directory on first run
In my app I added some code that will move a few folders from a source folder under images into the Documents folder when the app first runs.
The move works perfectly in the simulator, but does not work on an iPhone (running iOS 4.0.1).
Is this:
- a bug?
- a permissions loophole that the simulator is not supposed to allow?
- altogether the wrong way to go about adding initial data to the Documents folder in the first place?
3 Answers
-
I'll answer my own question…
Apparently, it is a permissions loophole. The Simulator allows something that the phone does not.
This article gave me a different way to go about accomplishing my objective:
http://anovice.com/2010/07/16/installing-app-files-with-appcelerator-titanium/ -
Since this post is no longer available in the web, I hunted it down at internet archive. Here is the bit that was helpful to me:
if (Ti.App.Properties.getInt("installComplete") == null) { var imgOriginal = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "/image.jpg"); var imgInstall = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + "/image.jpg"); imgInstall.write(imgOriginal); var dataOrig = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "/data.txt"); var dataInstall = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + "/data.txt"); var dataContent = dataOrig.read(); dataInstall.write(dataContent); Ti.App.Properties.setInt("installComplete", 1); }
-
hi, your question is very old may be you got answer till now but i wanna answer. there is a catch that you cannot move any file from resource directory , as move means you are removing it from resource directory, and titanium does not allow write permissions , so what you can do is read that whole file or directory and write it in the application data directory