I am constructing an iOS app the place customers should full an onboarding move earlier than accessing the primary residence display screen. Throughout onboarding, the person enters issues like nickname and nation.
After ending onboarding, I set a flag in UserDefaults:
UserDefaults.commonplace.set(true, forKey: "hasCompletedOnboarding")
print("hasCompletedOnboarding:", UserDefaults.commonplace.bool(forKey: "hasCompletedOnboarding"))
This accurately prints hasCompletedOnboarding: true.
In my SceneDelegate, I verify the flag like this:
let hasCompletedOnboarding = UserDefaults.commonplace.bool(forKey: "hasCompletedOnboarding")
If hasCompletedOnboarding is false, I present the onboarding. If it’s true, I present the primary interface.
The issue:
If I wait ~10 seconds, force-close the app, and reopen it, hasCompletedOnboarding is printing false in SceneDelegate, and the onboarding exhibits once more — regardless that I confirmed it was saved as true earlier than closing the app.
So UserDefaults seems to avoid wasting accurately throughout onboarding, however returns false after restarting.
What might trigger this? Am I lacking one thing in how UserDefaults works with SceneDelegate or app lifecycle? Any concepts or suggestions are appreciated.
