Saving user data to internal memory - Apple TV Swift

50 Views Asked by At

I am trying to save access token with in the application registry and getting saved success fully, but after rebooting the device and coming back to the device registry is getting cleared and user is taken back to the authentication page.

UserDefaults.standard.set(accessToken, forKey: "apiToken")
UserDefaults.standard.synchronize()

let apiToken = UserDefaults.standard.value(forKey: "apiToken")


1

There are 1 best solutions below

0
Jim Tierney On

To save a value to UserDefaults you need to create a value key

Unless you've already created some extension which is adding an additional property to UserDefaults.. "apiToken" that you've not shared here, you'll need to create it like this

UserDefaults.standard.set(accessToken, forKey: "apiToken")

You will then be able to retrieve this from

let apiToken = UserDefaults.standard.value(forKey: "apiToken")