We use UserDefaults in our app to identify if we already showed a particular UI to the user (so that it will not be shown to the user again). Our logic goes something like:
if !UserDefaults.standard.alreadyShownToUser {
showUI()
UserDefaults.standard.alreadyShownToUser = true
}
But there are users who see this particular screen again when they open the app. The screen does not show up for a few days, and then suddenly, it shows up again.
Our theory is that this might have something to do with iOS Prewarming. So we updated our code to add another check:
if UIApplication.shared.isProtectedDataAvailable && !UserDefaults.standard.alreadyShownToUser
However, it does NOT seem to work / mitigate the issue at all. We also added logs to check the value of UIApplication.shared.isProtectedDataAvailable
and the value of the UserDefaults variable.
We expected that if:
UIApplication.shared.isProtectedDataAvailable
is false, then the UserDefaults value should also be false.
But in our logs, we can see that
UIApplication.shared.isProtectedDataAvailable
is false, but UserDefaults still returned true.
Which led me to think that UserDefaults is not affected by Prewarming. Now, I'm back from the start.
What's causing our UserDefaults to have different value? We also do not have anywhere else in the app that sets the value of UserDefaults.standard.alreadyShownToUser
to false. The only time it should have that value is when the user installs the app for the first time.
I appreciate any help that can lead me to fix this issue. Thank you!