Save load not working in iOS but works in simulator?

Hello,

My save load works fine in simulator but doesn’t work in iOS. Does the code below have to be in main.lua? Because I am putting it under game.lua

local function onSystemEvent( event ) if ( event.type == "applicationSuspend" ) then sb.gameActive = false elseif ( event.type == "applicationResume" ) then sb.gameActive = true elseif ( event.type == "applicationExit" ) then saveGame() end end Runtime:addEventListener( "system", onSystemEvent )

perhaps the problem is in your save code everything looks fine here

It shouldn’t be the save code because it loads perfectly fine in the simulator. Once I install the dev version on my phone to test it out with xCode, nothing is saved after i quit the app and remove it from the background.

what directory are you saving the file to

I save it to: system.DocumentsDirectory

I am able to check the save file in the simulator at my library > application support > corona simulator > game name > documents

But the save just won’t trigger in the phone… I have no idea why.

you say it loads fine in sim. have you deleted the file from the sandbox then tried running in sim to make sure it creates the file when one doesnt exist

Yes, I deleted the save file from the sandbox and it created a new one

are you checking the file in the sandbox or checking it inside the game. i just noticed a similar issue with a save file. if i checked the file in the sandbox it was there with all the info but inside the app it was showing nothing was there.

So here is what happen:

Simulator:

  1. Start a fresh game,

  2. Quit to save

  3. Game saved

  4. Run the game again from cold start, game loads.

Phone:

  1. Start a fresh game,

  2. Quit to save

  3. Game not saved

  4. Run the game again from cold start, starts a fresh game

Accidentally double post instead of editing my previous one. I apologize.

I have been debugging in the xCode console with my iphone conencted to it. Here is something I noticed, if i kill the application from the background (using multitask menu), it doesn’t send an event saying the app has exit? Was it suppose to send an event? How do I track that?

Try adding saveGame() to the suspend function that way it’s save when it goes into the background

Yeap! I did that, and it solved my problem. This is because killing an app after suspending won’t send an event. Thanks for sticking around all the way and helping me solve it! Appreciate it :slight_smile:

Welcome
I should have caught that sooner I may have to punish myself

perhaps the problem is in your save code everything looks fine here

It shouldn’t be the save code because it loads perfectly fine in the simulator. Once I install the dev version on my phone to test it out with xCode, nothing is saved after i quit the app and remove it from the background.

what directory are you saving the file to

I save it to: system.DocumentsDirectory

I am able to check the save file in the simulator at my library > application support > corona simulator > game name > documents

But the save just won’t trigger in the phone… I have no idea why.

you say it loads fine in sim. have you deleted the file from the sandbox then tried running in sim to make sure it creates the file when one doesnt exist

Yes, I deleted the save file from the sandbox and it created a new one

are you checking the file in the sandbox or checking it inside the game. i just noticed a similar issue with a save file. if i checked the file in the sandbox it was there with all the info but inside the app it was showing nothing was there.