@@ -99,35 +99,45 @@ struct LocalStorage: LocalStorageProtocol {
99
99
private let keychain : IterableKeychain
100
100
101
101
private func moveAuthDataFromUserDefaultsToKeychain( ) {
102
- // in the future, use the migration function from IterableUserDefaults like with the last push payload
102
+ let ( userDefaultEmail , userDefaultUserId , userDefaultAuthToken ) = iterableUserDefaults . getAuthDataForMigration ( )
103
103
104
- if let userDefaultAuthToken = iterableUserDefaults. authToken, keychain. authToken == nil {
105
- keychain. authToken = userDefaultAuthToken
106
- iterableUserDefaults. authToken = nil
104
+ if let userDefaultEmail = userDefaultEmail {
105
+ if keychain. email == nil {
106
+ keychain. email = userDefaultEmail
107
+ }
107
108
108
- ITBInfo ( " UPDATED: moved authToken from UserDefaults to IterableKeychain " )
109
- }
110
-
111
- if let userDefaultEmail = iterableUserDefaults. email, keychain. email == nil {
112
- keychain. email = userDefaultEmail
113
109
iterableUserDefaults. email = nil
114
110
115
- ITBInfo ( " UPDATED: moved email from UserDefaults to IterableKeychain " )
111
+ ITBInfo ( " UPDATED: migrated email from UserDefaults to IterableKeychain " )
116
112
}
117
113
118
- if let userDefaultUserId = iterableUserDefaults. userId, keychain. userId == nil {
119
- keychain. userId = userDefaultUserId
114
+ if let userDefaultUserId = userDefaultUserId {
115
+ if keychain. userId == nil {
116
+ keychain. userId = userDefaultUserId
117
+ }
118
+
120
119
iterableUserDefaults. userId = nil
121
120
122
- ITBInfo ( " UPDATED: moved userId from UserDefaults to IterableKeychain " )
121
+ ITBInfo ( " UPDATED: migrated userId from UserDefaults to IterableKeychain " )
122
+ }
123
+
124
+ if let userDefaultAuthToken = userDefaultAuthToken {
125
+ if keychain. authToken == nil {
126
+ keychain. authToken = userDefaultAuthToken
127
+ }
128
+
129
+ iterableUserDefaults. authToken = nil
130
+
131
+ ITBInfo ( " UPDATED: migrated authToken from UserDefaults to IterableKeychain " )
123
132
}
124
133
}
125
134
126
135
private func moveLastPushPayloadFromUserDefaultsToKeychain( ) {
127
- if let ( userDefaultLastPushPayload, expiration) = iterableUserDefaults. getLastPushPayloadAndExpirationPair ( ) {
136
+ if let ( userDefaultLastPushPayload, expiration) = iterableUserDefaults. getLastPushPayloadExpirationPairForMigration ( ) {
128
137
keychain. setLastPushPayload ( userDefaultLastPushPayload, withExpiration: expiration)
138
+ iterableUserDefaults. save ( payload: nil , withExpiration: nil )
129
139
130
- ITBInfo ( " UPDATED: moved lastPushPayload from UserDefaults to IterableKeychain " )
140
+ ITBInfo ( " UPDATED: migrated lastPushPayload from UserDefaults to IterableKeychain " )
131
141
}
132
142
}
133
143
}
0 commit comments