In our application, we store user information (Username, Password, accessToken, Refresh token, etc.) in the keychain. However, after performing a hard reboot (unplugging and plugging back in), when we attempt to retrieve the ‘refresh token’ or ‘access token’ from the keychain, we receive the old token instead of the newly saved one.
Issue with Retrieving Updated Tokens from Keychain After Hard Reboot on Apple TV
Apple TV is a bit weird because a) it’s an iOS-style device, and b) you can yank the power. Normally, iOS-style devices have a battery and, even in the case wehre you run the battery completely down, the system usually has enough power to shut down cleanly.
Given that, I suspect keychain is not doing a sufficiently good job of synching its changes to disk. Under the cover the data protection keychain is implemented as an SQLite database. SQLite use a journal so that, if things go south, it’ll either roll forward or roll back to a consistent state. The most likely cause of the symptoms you’ve described is that it’s chosen to roll back.
IMO we could do a better job with this, especially given the realities of Apple TV. I think this’ll likely end up as a bug report. However, before I send you down that path, I thought I’d check whether you can reproduce this in a small test project?
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Apple TV is a bit weird because a) it’s an iOS-style device, and b) you can yank the power. Normally, iOS-style devices have a battery and, even in the case wehre you run the battery completely down, the system usually has enough power to shut down cleanly.
Given that, I suspect keychain is not doing a sufficiently good job of synching its changes to disk. Under the cover the data protection keychain is implemented as an SQLite database. SQLite use a journal so that, if things go south, it’ll either roll forward or roll back to a consistent state. The most likely cause of the symptoms you’ve described is that it’s chosen to roll back.
IMO we could do a better job with this, especially given the realities of Apple TV. I think this’ll likely end up as a bug report. However, before I send you down that path, I thought I’d check whether you can reproduce this in a small test project? Such a project might:
-
Read and displays the keychain item an launch.
-
Have a button that sets the keychain item to a string represent of the current date.
You could then launch it, click the button, pull the plug, launch it again, and see what you get.
The benefit of having a small test project like this is that it isolate this keychain problem from all the other code in your main app.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"