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

There are a few folks talking about the same issue:

An older Apple dev forum thread about prewarming (is this still relevant?)
https://forums.developer.apple.com/forums/thread/667959?page=2

StackOverflow post where folks blame a missing privacy manifest, but that doesn’t make sense does it?
https://stackoverflow.com/questions/77301047/ios-17-userdefaults-getting-cleared-on-relaunching-the-app

#iosdev #userdefaults

Lost data in UserDefaults | Apple Developer Forums

@adam they are starting to send out emails when you upload a TestFlight build saying you’re not in compliance but you don’t have to do anything yet because of the privacy manifest. It says we have until May to act.
@MuseumShuffle Also won’t it impact new uploads, not existing versions? It doesn’t seem relevant to the bug I’m seeing at all, but folks have confidently posted is as the solution in several places 😵‍💫
@adam that would be my thinking also. (That it’s not relevant)
@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
@adam All my drafts disappeared from @ivory, but all the other settings remained. Not sure if this was something caused by an app update or a system bug.
@arroz @ivory That’s interesting (and a bummer, obviously). As far as I know from the reports I’ve gotten about my app, it seems like all of UserDefaults is blown away: standard, my shared suite, RevenueCat’s suite, etc. But it’s possible those were all cleared because my code tried to use them all at some “inopportune” time.
@adam @ivory Apparently it lost other settings as well, like the single tap to boost. Somehow the account information survived. It’s smelling like an OS bug for sure.
@adam @ivory It didn’t loose ALL the settings though. Weird.
@arroz @adam We intentionally reset single tap to boost so users could see the new quote option. Otherwise people with that setting on would most likely report not having the option to quote as a bug.
@ivory @adam Right, I forgot about that. 🤦‍♂️ Still using the copy URL / paste method. 😄
@arroz You are the second person to report that they lost all their drafts though. Something we will look into.
@ivory @arroz it’s not everyone…which I know is good and bad news in troubleshooting ⚖️