Has anyone else been getting reports of their iOS app’s data just… vanishing? Specifically, it sounds like UserDefaults is being reset. This doesn’t seem to be hitting a lot of my users, but the ones it hits are seeing it over and over.
#iosdev #userdefaults
@adam Maybe @Catfish_Man knows? We've not heard anything where I work.

@jaredsinclair @adam I haven't worked on UserDefaults since 2018, but historically a leading cause of issues like this was "something causes the app to be launched before first unlock, when defaults aren't readable".

One other cause was cfprefsd running out of file descriptors, but that only happened once and I fixed it in a way that I think would be fairly difficult to re-break.

@Catfish_Man Thanks for the reply! Unless there is a specific iOS bug behind this, my guess is that it’s the “app launch before first unlock” that’s happening. If so, something must have changed in iOS 17.x that’s causing this to happen now, somewhere… but where? My widget extension? Intents extension? Something with live activities?

(Can an extension launching before first unlock blow away user defaults for the whole app?)

@adam it would be an OS bug regardless since it’s not supposed to put apps in that situation.

The workaround if that’s the case would be to make sure you detect empty defaults and don’t write to them, and then they’ll be back when you launch for real. The permanence of it is setting a value into the empty defaults, causing it to be written out to disk.

@Catfish_Man Ah okay, that makes sense. Would you expect them to be totally empty, like dictionaryRepresentation() is empty?
@adam there would probably be backstop values for AppleLanguages and AppleLocale