File storage

Have had great success porting my upcoming platformer to the tvOS.

But one issue i cannot workaround, there is no persistent storage on tvOS, so all the io* calls do not work.

As far as i have been able to understand, only option is to use NSUserDefaults then you have 500kb of storage

I know this is early grounds, but just wanted you to have this on the radar, as saving a games state is pretty important i think

Keep up the good work :slight_smile:

Yes, this is my number one concern. All our apps are well under the 200MB limit but we need a solution for local storage for saving preferences. If there’s no solution for this, we won’t have the option to use IAPs.

I got a first version of “Freeze! 2 - Brothers” working on the Apple TV, but I have the same problems saving my settings and values. 

Xcode gives me this error:

Nov 13 21:15:30 Apple-TV kernel[0] <Notice>: Sandbox: Freeze 2-ZIP tvO(178) deny(1) file-write-create /private/var/mobile/Containers/Data/Application/13B65E7C-4BC7-4513-8D84-3C8D55DBC506/Documents/settings.json 

I simply need this to store the progress of the user, that e.g. he is in World 03 in Level 17 and I need to store all the level times.

So I don’t even need 500KB, 5KB would be enough.

But without the chance to save stats no games are possible.

Maybe that’s the reason why the cool Coronalabs team started work on iCloud saves today.  :-)

But if we can get 500KB with NSUserDefaults like thassman wrote it would be perfect, too, and maybe faster to implement.

Thanks & best


I’m going to throw out an option here. Regardless of what ever we do with iCloud, your Apple TV pretty much has to be network connected. or setting up your own server and store whatever you want.  NSUserDefaults should not be hard to implement in Enterprise.

NSUserDefaults will have a 0.5mb limit

CloudKit’s Key-Value pairs will have a 1mb limit

Finally, while there seems to be no local data store, Apple does talk about the caches directory.  Have you tried to open/close files in system.CachesDirectory?


I do have a backend where i can store the games state.

But how do i get a unique id for the device, it has to be something that is returned by the OS, cause i cannot create it myself and save it locally as i normally would do.



There is the OpenUDID plugin (iOS only) that will work. system.getInfo() has a “deviceID” option which should return an allowed unique ID that can be used. Of how about a novel idea, don’t tie it to the device at all, but to a user ID. That way people on Android devices that support multiple users won’t interfere with other user’s saved data. If someone gets a new device, since it’s tied to the user, not the device, they can pick up where they left off.



thanks for implementing iCloud-Key-Value-Storage, this really is great, I now will use this for “Freeze!” and “Freeze! 2 - Brothers” so the game progress is synced across all devices, even between the phone/tablet and upcoming tvOS versions.

But we still need access to NSUserDefaults:

This is important according to Apple if the Apple TV is offline - the game still needs to know about the selected language, the current level of the game etc.

So the correct way to set this up is:

1.) save all the info (level progress etc.) you need for the player to continue his game locally using NSUserDefaults

2.) additionally save all this stuff using iCloud KVS to sync with the same game on phone/tablet

If Apple tv is online use the iCloud KVS values, if offline use the local backup from NSUserDefaults.

To set this up should be much less effort than implementing iCloud KVS - and again, thanks for that, will start to work with this now. :slight_smile:



We have a feature request for this at:

But it doesn’t have a lot of votes. Engineering said this should be easy to implement, but we just have to get it in the work queue.


Hi Rob,

thanks for the tip, I just voted.

I guess when more dev will target tvOS this will get more important.



I just voted as well.  This really is something that should be standard.  Other items, IMHO, like Game Center should require popular vote…

[quote name=“JonPM” post=“314687” timestamp=“1450662835”]I just voted as well.  This really is something that should be standard.  Other items, IMHO, like Game Center should require popular vote…[/quote] Hi Jon, thanks for upvoting NSUserDefaults! But on Game Cente support I strongly disagree, every game that needs to be taken seriously has to have at least Leaderboards and Achievements. It’s not so much about the players (don’t get me wrong, many love & demand this), it’s more about Apple: It’s even harder to get picked by the Apple Editorial Team for a feature if you don’t support basics like Game Center. They need stories, like “Freeze! 2 now is available for iOS and tvOS, and game progress, Achievements & Leaderboards are shared across all devices!”. With stories like this they will promote their Apple TV, and if you cannot deliver this promise they just will pick another game for a promotion. I will only publish the tvOS version of the game when I can support Game Center, otherwise my chance to be featured might be gone.

Hi! I voted for NSUserDefaults, too. Support für Game Center on tvOS is also important for us. :slight_smile:

I am not saying Game Center is not important, because it is.  I’m merely saying the need to save data locally is a very basic necessity in comparison.  As you said, every game that needs to be taken seriously needs GC, but in contrast, every game needs local file storage.  If the Apple tvOS reviewers review apps in the same manner as they do iOS (i.e. in airplane mode), then lacking local persistent data storage could be grounds for rejection.  

Hi Jon, of course, that’s what I’m saying, read my earlier post about Apple expecting the apps to work offline. Because of this NSUserDefaults should have a high priority. I just objected to your suggestion to throw Game Center at the mercy of votes. And this in a threat about NSUserDefaults. :wink: Best Andreas

What is the status for io.* capabilities for tvOS?

io* should work with system.CachesDirectory, system.TemporaryDirectory and system.ResourceDirectory. Anything else needs to go to iCloud.


So there is no system.DocumentsDirectory for tvOS? What takes it place?

The bulk of this thread deals with the fact that there is a very small amount of local storage available to tvOS apps. See below thread for details:

I only need a small amount to store a high score. I looked through the thread you provided but I did not see a solution for local persistent data.

This is  the thread that is discussing possible solutions/workarounds regarding local file storage for tvOS. You can read through this thread to get a feel for how tvOS development has been progressing, including resources about tvOS and it’s various challenges. Rob Miracle created a tutorial here that talks about how to use the iCloud plugin so that Corona developers can target tvOS distribution.