Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use NSUserDefaults with tvOS?

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?

like image 567
jtbandes Avatar asked Sep 18 '15 05:09

jtbandes


People also ask

What types can you store natively in NSUserDefaults?

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.

Is UserDefaults shared between apps?

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.

Is NSUserDefaults thread safe?

The NSUserDefaults class is thread-safe.

What is NSUserDefaults?

NSUserDefaults is a hierarchical persistent interprocess (optionally distributed) key-value store, optimized for storing user settings.

What is the use of nsuserdefaults?

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”.

How to compile code only when building for tvOS?

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.");

What types of objects can I save with nsuserdefaults?

With NSUserDefaults you can save objects from the following class types: NSData NSString NSNumber NSDate NSArray NSDictionary

What is the maximum size for a tvOS app bundle?

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.


2 Answers

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

like image 138
vegashacker Avatar answered Oct 06 '22 18:10

vegashacker


You can use NSUserDefaults for TVOS as per documentation.

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/UserDefaults/AccessingPreferenceValues/AccessingPreferenceValues.html

like image 26
Usama Avatar answered Oct 06 '22 19:10

Usama