Hi Dewey,
The Documents folder doesn’t exist until the user installs the app on the device. You’ll have to copy the file from the Resources directory to the Documents directory the first time the user launches the app.
However, I wouldn’t start copying anything over or performing any heavy lifting at init time because, as you know, the OS would kill your app for taking to long to start. You can get around this by giving your app the chance to fully load and then initiate any in-depth processes in a subsequent frame. You can do this by using an event listener:
--this function does a lot of the heavy lifting
local function loadData()
--kill the event listener since this function only needs to run once
Runtime:removeEventListener("enterFrame", loadData)
--perform heavy lifting
--[heavy lifting code goes here]--
end
--this function sets up the app and triggers the heavy lifting function
local function init()
--perform some basic setup, such as placing the nav, tab bar, etc.
--[setup code goes here]--
--trigger the heavy lifting function
Runtime:addEventListener("enterFrame", loadData)
end
--now start the program
init()
You may also want to throw in a function before all of this that checks to see if this is the first time the app has run and if not to run a check for your data file, and if the data file is missing, reload it (because the user could have also deleted your data from the Documents folder directly. They have access to it in iTunes and can do that.)
The ATA app is a good example of an app that checks for and restores a previous state. Take a look at the main.lua file: https://github.com/gg-ansca/ATA/blob/master/main.lua
The other option to using event listeners is to use timer.performWithDelay().
local function loadData()
--perform heavy lifting
--[heavy lifting code goes here]--
end
local function init()
--perform some basic setup, such as placing the nav, tab bar, etc.
--[setup code goes here]--
--trigger the heavy lifting after a few milliseconds
timer.performWithDelay(50, loadData )
end
--start the program
init()
-Gilbert [import]uid: 5917 topic_id: 4704 reply_id: 15103[/import]