@@ -124,32 +124,52 @@ struct CurrentInstallationContainer<T: ParseInstallation>: Codable {
124
124
125
125
// MARK: Current Installation Support
126
126
extension ParseInstallation {
127
- static var currentInstallationContainer : CurrentInstallationContainer < Self > {
127
+ static var currentContainer : CurrentInstallationContainer < Self > {
128
128
get {
129
129
guard let installationInMemory: CurrentInstallationContainer < Self > =
130
- try ? ParseStorage . shared. get ( valueFor: ParseStorage . Keys. currentInstallation) else {
130
+ try ? ParseStorage . shared. get ( valueFor: ParseStorage . Keys. currentInstallation) else {
131
131
#if !os(Linux) && !os(Android)
132
- guard let installationFromKeyChain: CurrentInstallationContainer < Self > =
132
+ guard let installationFromKeyChain: CurrentInstallationContainer < Self > =
133
133
try ? KeychainStore . shared. get ( valueFor: ParseStorage . Keys. currentInstallation)
134
- else {
135
- var newInstallation = CurrentInstallationContainer < Self > ( )
136
- let newInstallationId = UUID ( ) . uuidString. lowercased ( )
137
- newInstallation. installationId = newInstallationId
138
- newInstallation. currentInstallation? . createInstallationId ( newId: newInstallationId)
139
- newInstallation. currentInstallation? . updateAutomaticInfo ( )
140
- try ? KeychainStore . shared. set ( newInstallation, for: ParseStorage . Keys. currentInstallation)
141
- try ? ParseStorage . shared. set ( newInstallation, for: ParseStorage . Keys. currentInstallation)
142
- return newInstallation
134
+ else {
135
+ let newInstallationId = UUID ( ) . uuidString. lowercased ( )
136
+ var newInstallation = BaseParseInstallation ( )
137
+ newInstallation. installationId = newInstallationId
138
+ newInstallation. createInstallationId ( newId: newInstallationId)
139
+ newInstallation. updateAutomaticInfo ( )
140
+ let newBaseInstallationContainer =
141
+ CurrentInstallationContainer < BaseParseInstallation > ( currentInstallation: newInstallation,
142
+ installationId: newInstallationId)
143
+ try ? KeychainStore . shared. set ( newBaseInstallationContainer,
144
+ for: ParseStorage . Keys. currentInstallation)
145
+ guard let installationFromKeyChain: CurrentInstallationContainer < Self > =
146
+ try ? KeychainStore . shared. get ( valueFor: ParseStorage . Keys. currentInstallation)
147
+ else {
148
+ // Couldn't create container correctly, return empty one.
149
+ return CurrentInstallationContainer < Self > ( )
143
150
}
151
+ try ? ParseStorage . shared. set ( installationFromKeyChain, for: ParseStorage . Keys. currentInstallation)
144
152
return installationFromKeyChain
153
+ }
154
+ return installationFromKeyChain
145
155
#else
146
- var newInstallation = CurrentInstallationContainer < Self > ( )
147
- let newInstallationId = UUID ( ) . uuidString. lowercased ( )
148
- newInstallation. installationId = newInstallationId
149
- newInstallation. currentInstallation? . createInstallationId ( newId: newInstallationId)
150
- newInstallation. currentInstallation? . updateAutomaticInfo ( )
151
- try ? ParseStorage . shared. set ( newInstallation, for: ParseStorage . Keys. currentInstallation)
152
- return newInstallation
156
+ let newInstallationId = UUID ( ) . uuidString. lowercased ( )
157
+ var newInstallation = BaseParseInstallation ( )
158
+ newInstallation. installationId = newInstallationId
159
+ newInstallation. createInstallationId ( newId: newInstallationId)
160
+ newInstallation. updateAutomaticInfo ( )
161
+ let newBaseInstallationContainer =
162
+ CurrentInstallationContainer < BaseParseInstallation > ( currentInstallation: newInstallation,
163
+ installationId: newInstallationId)
164
+ try ? ParseStorage . shared. set ( newBaseInstallationContainer,
165
+ for: ParseStorage . Keys. currentInstallation)
166
+ guard let installationFromMemory: CurrentInstallationContainer < Self > =
167
+ try ? ParseStorage . shared. get ( valueFor: ParseStorage . Keys. currentInstallation)
168
+ else {
169
+ // Couldn't create container correctly, return empty one.
170
+ return CurrentInstallationContainer < Self > ( )
171
+ }
172
+ return installationFromMemory
153
173
#endif
154
174
}
155
175
return installationInMemory
@@ -160,19 +180,19 @@ extension ParseInstallation {
160
180
}
161
181
162
182
internal static func updateInternalFieldsCorrectly( ) {
163
- if Self . currentInstallationContainer . currentInstallation? . installationId !=
164
- Self . currentInstallationContainer . installationId! {
183
+ if Self . currentContainer . currentInstallation? . installationId !=
184
+ Self . currentContainer . installationId! {
165
185
//If the user made changes, set back to the original
166
- Self . currentInstallationContainer . currentInstallation? . installationId =
167
- Self . currentInstallationContainer . installationId!
186
+ Self . currentContainer . currentInstallation? . installationId =
187
+ Self . currentContainer . installationId!
168
188
}
169
189
//Always pull automatic info to ensure user made no changes to immutable values
170
- Self . currentInstallationContainer . currentInstallation? . updateAutomaticInfo ( )
190
+ Self . currentContainer . currentInstallation? . updateAutomaticInfo ( )
171
191
}
172
192
173
193
internal static func saveCurrentContainerToKeychain( ) {
174
194
#if !os(Linux) && !os(Android)
175
- try ? KeychainStore . shared. set ( Self . currentInstallationContainer , for: ParseStorage . Keys. currentInstallation)
195
+ try ? KeychainStore . shared. set ( Self . currentContainer , for: ParseStorage . Keys. currentInstallation)
176
196
#endif
177
197
}
178
198
@@ -182,7 +202,7 @@ extension ParseInstallation {
182
202
try ? KeychainStore . shared. delete ( valueFor: ParseStorage . Keys. currentInstallation)
183
203
#endif
184
204
//Prepare new installation
185
- _ = BaseParseInstallation ( )
205
+ BaseParseInstallation . createNewInstallationIfNeeded ( )
186
206
}
187
207
188
208
/**
@@ -192,10 +212,10 @@ extension ParseInstallation {
192
212
*/
193
213
public static var current : Self ? {
194
214
get {
195
- return Self . currentInstallationContainer . currentInstallation
215
+ return Self . currentContainer . currentInstallation
196
216
}
197
217
set {
198
- Self . currentInstallationContainer . currentInstallation = newValue
218
+ Self . currentContainer . currentInstallation = newValue
199
219
Self . updateInternalFieldsCorrectly ( )
200
220
}
201
221
}
0 commit comments