I am using GGData in order to save user data that I want to persist between user sessions of my application after my application has been closed and reopened. When I run my application in the simulator, the user data persists after I close or relaunch the simulator. However, when building and testing my application on an iPhone iOS device, the user settings do not persist. In other words, when I close the application completely, and reopen it the application does not preserve any of the user settings I had altered manually during the previous session. So far, I have not been able to find any reason online why user data would persist on the simulator, but not when running an application on a device. Below is a sample of the code I have been using in my main.lua file to save user data that I want to persist between user sessions:
local myData = require( “myData” )
local GGData = require( “GGData” )
local box = GGData:new( “storage” )
local function defaultValues()
myData.soundIndex = 1
myData.uiBackgroundIndex = 1
myData.exitCount = nil
end
defaultValues()
local function saveBox()
box.uiBackgroundIndex = myData.uiBackgroundIndex
box.soundIndex = myData.soundIndex
box.exitCount = myData.exitCount
box:save()
end
local function setValues()
myData.uiBackgroundIndex = box.uiBackgroundIndex
myData.soundIndex = box.soundIndex
myData.exitCount = box.exitCount
end
local function onSystemEvent( event )
if ( event.type == “applicationStart” ) then
if box.exitCount ~= nil then
setValues()
end
elseif ( event.type == “applicationExit” ) then
if myData.exitCount == nil then
print(“first time closed”)
myData.exitCount = 1
print( "exitCount = "…myData.exitCount)
else
myData.exitCount = myData.exitCount + 1
print( "exitCount = "…myData.exitCount)
end
saveBox()
end
end
Runtime:addEventListener( “system”, onSystemEvent )