The App Programming Guide for tvOS briefly states that
There is no persistent local storage for apps on Apple TV. This means that every app developed for the new Apple TV must be able to store data in iCloud and retrieve it in a way that provides a great customer experience.
Does this mean NSUserDefaults is unavailable? What mechanisms are available for data storage?
Storing Default Objects The NSUserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Boolean values, and URLs. These methods are described in Setting Default Values.
Sharing data within an app groupThe first thing that using UserDefaults will allow us to do, is to easily share data between multiple apps and app extensions.
The NSUserDefaults class is thread-safe.
NSUserDefaults is a hierarchical persistent interprocess (optionally distributed) key-value store, optimized for storing user settings.
With the NSUserDefaults class, you can save settings and properties related to application or user data. For example, you could save a profile image set by the user or a default color scheme for the application. The objects will be saved in what is known as the iOS “defaults system”.
To conditionalize code so that it is only compiled for tvOS, use the TARGET_OS_TV macro or one of the tvOS version constants defined in Availability.h. In an app written in Swift, use a build configuration statement or an API availability statement. NSLog(@"Code compiled only when building for tvOS.");
With NSUserDefaults you can save objects from the following class types: NSData NSString NSNumber NSDate NSArray NSDictionary
The maximum size for a tvOS app bundle 4 GB. Moreover, your app can only access 500 KB of persistent storage that is local to the device (using the NSUserDefaults class). Outside of this limited local storage, all other data must be purgeable by the operating system when space is low.
According to an Apple Staff member on the devforums, you can use NSUserDefaults on tvOS for up to 500 kb of data:
https://forums.developer.apple.com/message/50696#50696
You can use NSUserDefaults for TVOS as per documentation.
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/UserDefaults/AccessingPreferenceValues/AccessingPreferenceValues.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With