No local storage, what about settings, state?

According to this: https://developer.apple.com/library/prerelease/tvos/documentation/General/Conceptual/AppleTV_PG/


There is no persistent local storage for apps on the Apple TV.


This seems somewhat odd. What if I have an app with different settings customized to the user? Do they lose all those settings? Or is there a special case for something like NSUserDefaults?

Answered by Technology Evangelist in 50696022

NSUserDefaults is allowed, and supports up to 500KB of data.


You can also store content locally using the application temp and cache directories, but note that this data will be purged.


Beyond the above 500 KB limit, you will need to utilize either CloudKit or some other off device means of data storage. This could include your own web services implementation, for example.

A small amount of data can be stored using NSUserDefaults.

Can you define small? :-)

I believe 1MB...

"For large storage needs, greater than 1MB, your app needs to implement CloudKit."

I'm not sure that NSUserDefaults is allowed. According to the "Managing Resources" link, iCloud KVS is required.


It'd be nice to get some clarification.

what about the scenario where the apple tv is connected to an offline (no internet) LAN and the app needs to access and download content on the LAN that is not specific to a user?

I doubt that is a scenario Apple cares about. No internet, not app store, and no iTunes revenue.

Accepted Answer

NSUserDefaults is allowed, and supports up to 500KB of data.


You can also store content locally using the application temp and cache directories, but note that this data will be purged.


Beyond the above 500 KB limit, you will need to utilize either CloudKit or some other off device means of data storage. This could include your own web services implementation, for example.

Pretty disappointing that we can't use persistent local storage, but it's good to know we can still cache data to temp/cache directories.


But when does the temp/cache purge happen? Only when the available storage space is running low? On app launch? Another method?


Thank you.

Your app can download whatever data it needs and save it to its Cache directory. That data will not be deleted out from underneath a running application. However, it may get deleted while your app is not running if the system needs space.

There are no guarantees as to timing of this, but generally you would see the behaviour when rebooting the device or when the device is constrained for resources and your app isn't running.


Content that you do not want purged in this way should be included in the app bundle, or loaded via On Demand Resources, which will offer you greater control over the prioriziation of the purging of the content.

Which basically severely limits read/write database support for sqlite 😟

Can we persistently store password data to the keychain?

Yes, the keychain is persistent.

No local storage, what about settings, state?
 
 
Q