AppAuth-iOS
AppAuth-iOS copied to clipboard
Fixing the unarchivedObject
trafficstars
NSCoder is not very good at decoding heterogeneous objects.. With this work the issue with decodeObject is fixed as result of which NSKeyedUnarchiver.unarchivedObject(ofClass: OIDAuthState.self, from: decoded) throws should work as expected.
This PR is relate to the issue https://github.com/openid/AppAuth-iOS/issues/479
Thank you! I can confirm this is working for me.
static let userDefaultSuiteName = "group.net.openid.appauth.XYZOAuth"
private var authState: OIDAuthState? {
didSet {
if let authState = authState,
let userDefaults = UserDefaults(suiteName: XYZOAuth.userDefaultSuiteName),
let data = try? NSKeyedArchiver.archivedData(withRootObject: authState, requiringSecureCoding: true) {
userDefaults.set(data, forKey: "authState")
userDefaults.synchronize()
}
}
}
let instance = XYZOAuth()
if let data = UserDefaults(suiteName: XYZOAuth.userDefaultSuiteName)?.object(forKey: "authState") as? Data,
let authStateSaved = try? NSKeyedUnarchiver.unarchivedObject(ofClass: OIDAuthState.self, from: data) {
instance.authState = authStateSaved
}
return instance
Thanks for the PR. #479 has been addressed in the 1.6.0 release.