Can I use NSUserDefaults with tvOS?

后端 未结 5 2114
囚心锁ツ
囚心锁ツ 2020-12-15 20:57

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 d

相关标签:
5条回答
  • 2020-12-15 21:05

    To follow up @vegashacker's answer, the same Apple staff member also said:

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

    The purge is likely to happen when you app is no longer running, e.g. when resources are under pressure, or at reboot.

    0 讨论(0)
  • 2020-12-15 21:06

    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

    0 讨论(0)
  • You can use NSUserDefaults for TVOS as per documentation.

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

    0 讨论(0)
  • 2020-12-15 21:14

    Apple really wants you (and AppleTV customers) to sign up for and use iCloud.

    Here is the current documentation on what to do for persistent storage with AppleTV.

    The introductory paragraph:

    Storage on Apple TV is limited, and there is no guarantee that information stored on the device will be available the next time a user opens your app. Also, in order to share the user’s data across multiple devices, you need to store the user’s information somewhere other than the Apple TV. Apple provides two shared storage options for Apple TV: iCloud Key-Value Storage (KVS), and CloudKit.

    For files less than 1 meg, you'll use iCloud Key-Value Storage (KVS). For storage more than 1 Meg, you'll use CloudKit.

    0 讨论(0)
  • 2020-12-15 21:24

    NSUserDefaults is available but has a limited size on tvOS. According to Apple staff on forum "NSUserDefaults is allowed, and supports up to 500KB of data." and also "The behaviour is the same as on iOS: NSUserDefaults is persistent as long as the user does not delete the app from the device."

    Also according to NSUserDefaults.h header "NSUserDefaultsSizeLimitExceededNotification is posted on the main queue when more data is stored in user defaults than is allowed. Currently there is no limit for local user defaults except on tvOS, where a warning notification will be posted at 512kB, and the process terminated at 1MB. For ubiquitous defaults, the limit depends on the logged in iCloud user."

    0 讨论(0)
提交回复
热议问题