@@ -61,23 +61,24 @@ public class ParseRemote: OCKRemoteSynchronizable {
61
61
Requires `ParseLiveQuery` server to be setup.
62
62
- defaultACL: The default access control list for which users can access or modify `ParseCareKit`
63
63
objects. If no `defaultACL` is provided, the default is set to read/write for the user who created the data with
64
- no public read/write access. This `defaultACL` is not the same as `ParseACL.defaultACL`. If you want the
65
- the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`, you need to provide
66
- `ParseACL.defaultACL`.
64
+ no public read/write access.
65
+ - important: This `defaultACL` is not the same as `ParseACL.defaultACL`.
66
+ - note: If you want the the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`,
67
+ you need to provide `ParseACL.defaultACL`.
67
68
*/
68
69
public init ( uuid: UUID ,
69
70
auto: Bool ,
70
71
subscribeToServerUpdates: Bool ,
71
- defaultACL: ParseACL ? = nil ) throws {
72
+ defaultACL: ParseACL ? = nil ) async throws {
72
73
self . pckStoreClassesToSynchronize = try PCKStoreClass . patient. getConcrete ( )
73
74
self . customClassesToSynchronize = nil
74
75
self . uuid = uuid
75
76
self . clockQuery = PCKClock . query ( ClockKey . uuid == uuid)
76
77
self . automaticallySynchronizes = auto
77
78
self . subscribeToServerUpdates = subscribeToServerUpdates
78
- if let currentUser = PCKUser . current {
79
- Self . setDefaultACL ( defaultACL, for: currentUser)
80
- subscribeToClock ( )
79
+ if let currentUser = try ? await PCKUser . current ( ) {
80
+ try Self . setDefaultACL ( defaultACL, for: currentUser)
81
+ await subscribeToClock ( )
81
82
}
82
83
}
83
84
@@ -91,19 +92,20 @@ public class ParseRemote: OCKRemoteSynchronizable {
91
92
Requires `ParseLiveQuery` server to be setup.
92
93
- defaultACL: The default access control list for which users can access or modify `ParseCareKit`
93
94
objects. If no `defaultACL` is provided, the default is set to read/write for the user who created the data with
94
- no public read/write access. This `defaultACL` is not the same as `ParseACL.defaultACL`. If you want the
95
- the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`, you need to provide
96
- `ParseACL.defaultACL`.
95
+ no public read/write access.
96
+ - important: This `defaultACL` is not the same as `ParseACL.defaultACL`.
97
+ - note: If you want the the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`,
98
+ you need to provide `ParseACL.defaultACL`.
97
99
*/
98
100
convenience public init ( uuid: UUID ,
99
101
auto: Bool ,
100
102
replacePCKStoreClasses: [ PCKStoreClass : PCKSynchronizable ] ,
101
103
subscribeToServerUpdates: Bool ,
102
- defaultACL: ParseACL ? = nil ) throws {
103
- try self . init ( uuid: uuid,
104
- auto: auto,
105
- subscribeToServerUpdates: subscribeToServerUpdates,
106
- defaultACL: defaultACL)
104
+ defaultACL: ParseACL ? = nil ) async throws {
105
+ try await self . init ( uuid: uuid,
106
+ auto: auto,
107
+ subscribeToServerUpdates: subscribeToServerUpdates,
108
+ defaultACL: defaultACL)
107
109
try self . pckStoreClassesToSynchronize = PCKStoreClass
108
110
. patient. replaceRemoteConcreteClasses ( replacePCKStoreClasses)
109
111
self . customClassesToSynchronize = nil
@@ -121,20 +123,21 @@ public class ParseRemote: OCKRemoteSynchronizable {
121
123
Requires `ParseLiveQuery` server to be setup.
122
124
- defaultACL: The default access control list for which users can access or modify `ParseCareKit`
123
125
objects. If no `defaultACL` is provided, the default is set to read/write for the user who created the data with
124
- no public read/write access. This `defaultACL` is not the same as `ParseACL.defaultACL`. If you want the
125
- the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`, you need to provide
126
- `ParseACL.defaultACL`.
126
+ no public read/write access.
127
+ - important: This `defaultACL` is not the same as `ParseACL.defaultACL`.
128
+ - note: If you want the the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`,
129
+ you need to provide `ParseACL.defaultACL`.
127
130
*/
128
131
convenience public init ( uuid: UUID ,
129
132
auto: Bool ,
130
133
replacePCKStoreClasses: [ PCKStoreClass : PCKSynchronizable ] ? = nil ,
131
134
customClasses: [ String : PCKSynchronizable ] ,
132
135
subscribeToServerUpdates: Bool ,
133
- defaultACL: ParseACL ? = nil ) throws {
134
- try self . init ( uuid: uuid,
135
- auto: auto,
136
- subscribeToServerUpdates: subscribeToServerUpdates,
137
- defaultACL: defaultACL)
136
+ defaultACL: ParseACL ? = nil ) async throws {
137
+ try await self . init ( uuid: uuid,
138
+ auto: auto,
139
+ subscribeToServerUpdates: subscribeToServerUpdates,
140
+ defaultACL: defaultACL)
138
141
if replacePCKStoreClasses != nil {
139
142
self . pckStoreClassesToSynchronize = try PCKStoreClass
140
143
. patient. replaceRemoteConcreteClasses ( replacePCKStoreClasses!)
@@ -145,27 +148,29 @@ public class ParseRemote: OCKRemoteSynchronizable {
145
148
}
146
149
147
150
deinit {
148
- do {
149
- try clockQuery. unsubscribe ( )
150
- if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
151
- Logger . deinitializer. error ( " Unsubscribed from clock query " )
152
- } else {
153
- os_log ( " Unsubscribed from clock query " ,
154
- log: . deinitializer,
155
- type: . error)
156
- }
157
- } catch {
158
- if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
159
- Logger . deinitializer. error ( " Couldn't unsubscribe from clock query " )
160
- } else {
161
- os_log ( " Couldn't unsubscribe from clock query " ,
162
- log: . deinitializer,
163
- type: . error)
151
+ Task {
152
+ do {
153
+ try await clockQuery. unsubscribe ( )
154
+ if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
155
+ Logger . deinitializer. error ( " Unsubscribed from clock query " )
156
+ } else {
157
+ os_log ( " Unsubscribed from clock query " ,
158
+ log: . deinitializer,
159
+ type: . error)
160
+ }
161
+ } catch {
162
+ if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
163
+ Logger . deinitializer. error ( " Couldn't unsubscribe from clock query " )
164
+ } else {
165
+ os_log ( " Couldn't unsubscribe from clock query " ,
166
+ log: . deinitializer,
167
+ type: . error)
168
+ }
164
169
}
165
170
}
166
171
}
167
172
168
- class func setDefaultACL( _ defaultACL: ParseACL ? , for user: PCKUser ) {
173
+ class func setDefaultACL( _ defaultACL: ParseACL ? , for user: PCKUser ) throws {
169
174
let acl : ParseACL !
170
175
if let defaultACL = defaultACL {
171
176
acl = defaultACL
@@ -206,19 +211,35 @@ public class ParseRemote: OCKRemoteSynchronizable {
206
211
type: . error,
207
212
error. localizedDescription)
208
213
}
214
+ throw error
209
215
}
210
216
}
211
217
212
- func subscribeToClock ( ) {
213
- DispatchQueue . main . async {
214
-
215
- guard PCKUser . current != nil ,
216
- self . subscribeToServerUpdates == true ,
217
- self . clockSubscription == nil else {
218
+ @ MainActor
219
+ func subscribeToClock ( ) async {
220
+ do {
221
+ _ = try await PCKUser . current ( )
222
+ guard self . subscribeToServerUpdates == true ,
223
+ self . clockSubscription == nil else {
218
224
return
219
225
}
220
226
221
- guard let subscription = self . clockQuery. subscribeCallback else {
227
+ do {
228
+ let subscription = try await self . clockQuery. subscribeCallback ( )
229
+ self . clockSubscription = subscription
230
+ self . clockSubscription? . handleEvent { ( _, _) in
231
+ self . parseDelegate? . didRequestSynchronization ( self )
232
+ if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
233
+ Logger
234
+ . clockSubscription
235
+ . log ( " Parse subscription is notifying that there are updates on the server " )
236
+ } else {
237
+ os_log ( " Parse subscription is notifying that there are updates on the server " ,
238
+ log: . clockSubscription,
239
+ type: . info)
240
+ }
241
+ }
242
+ } catch {
222
243
if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
223
244
Logger . clockSubscription. error ( " Couldn't subscribe to clock query " )
224
245
} else {
@@ -228,32 +249,22 @@ public class ParseRemote: OCKRemoteSynchronizable {
228
249
}
229
250
return
230
251
}
231
- self . clockSubscription = subscription
232
- self . clockSubscription? . handleEvent { ( _, _) in
233
- self . parseDelegate? . didRequestSynchronization ( self )
234
- if #available( iOS 14 . 0 , watchOS 7 . 0 , * ) {
235
- Logger
236
- . clockSubscription
237
- . log ( " Parse subscription is notifying that there are updates on the server " )
238
- } else {
239
- os_log ( " Parse subscription is notifying that there are updates on the server " ,
240
- log: . clockSubscription,
241
- type: . info)
242
- }
243
- }
252
+ } catch {
253
+ return
244
254
}
245
255
}
246
256
247
257
public func pullRevisions( since knowledgeVector: OCKRevisionRecord . KnowledgeVector ,
248
258
mergeRevision: @escaping ( OCKRevisionRecord ) -> Void ,
249
259
completion: @escaping ( Error ? ) -> Void ) {
250
260
251
- guard PCKUser . current != nil else {
252
- completion ( ParseCareKitError . userNotLoggedIn)
253
- return
254
- }
255
-
256
261
Task {
262
+ do {
263
+ _ = try await PCKUser . current ( )
264
+ } catch {
265
+ completion ( ParseCareKitError . userNotLoggedIn)
266
+ return
267
+ }
257
268
do {
258
269
let status = try await ParseHealth . check ( )
259
270
guard status == . ok else {
@@ -293,7 +304,9 @@ public class ParseRemote: OCKRemoteSynchronizable {
293
304
let returnError : Error ? = nil
294
305
295
306
let localClock = knowledgeVector. clock ( for: self . uuid)
296
- self . subscribeToClock ( )
307
+ Task {
308
+ await self . subscribeToClock ( )
309
+ }
297
310
ParseRemote . queue. sync {
298
311
self . pullRevisionsForConcreteClasses ( previousError: returnError, localClock: localClock,
299
312
cloudVector: cloudVector,
@@ -411,20 +424,21 @@ public class ParseRemote: OCKRemoteSynchronizable {
411
424
public func pushRevisions( deviceRevision: OCKRevisionRecord ,
412
425
completion: @escaping ( Error ? ) -> Void ) {
413
426
414
- guard PCKUser . current != nil else {
415
- completion ( ParseCareKitError . userNotLoggedIn)
416
- return
417
- }
418
-
419
- guard deviceRevision. entities. count > 0 else {
420
- // No revisions need to be pushed
421
- self . isSynchronizing = false
422
- self . parseRemoteDelegate? . successfullyPushedDataToCloud ( )
423
- completion ( nil )
424
- return
425
- }
426
-
427
427
Task {
428
+ do {
429
+ _ = try await PCKUser . current ( )
430
+ } catch {
431
+ completion ( ParseCareKitError . userNotLoggedIn)
432
+ return
433
+ }
434
+
435
+ guard deviceRevision. entities. count > 0 else {
436
+ // No revisions need to be pushed
437
+ self . isSynchronizing = false
438
+ self . parseRemoteDelegate? . successfullyPushedDataToCloud ( )
439
+ completion ( nil )
440
+ return
441
+ }
428
442
do {
429
443
let status = try await ParseHealth . check ( )
430
444
guard status == . ok else {
0 commit comments