You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've really been enjoying the book and the sync codebase, and am building off it for our own project.
I'm building a remote type that uses Firebase instead of CloudKit. One thing I encountered is the following:
Object A created locally, recognized by Uploader Change Processor. Object A has a nilremoteIdentifier until it is successfully uploaded
Upload begins
Upload succeeds, but the completion block has not been fired and our app has not yet been notified of a successful upload
Object Added Change Subscription from Firebase notifies the app that we have a new object that was added to the remote destination
App adds the object from step (4) to the local store
Successful upload from step (2) returns to app, and remoteIdentifier is assigned to the local object created in step (1)
Expected result: we should have one object that has been successfully stored in the remote destination
Actual result: we have created two local objects with identical remoteIdentifier values, and there is one object at the remote destination.
I'm not sure this scenario is possible with the Moody sample app, or with CloudKit at all, because of the way remote push updates work with CloudKit. But with the way I added Firebase subscriptions / push updates, it's definitely happening for me.
Is this a scenario you contemplated or experienced at all during your work on the sample app? Do you have any ideas about how this could be avoided?
The text was updated successfully, but these errors were encountered:
Hi @timcamber — yes, that complicates things. We didn't anticipate this Cloud Kit behaviour.
What does the Object Added Change Subscription look like? Is there anything in there that lets you know that the addition originates from that very same device?
I'm not a Firebase expert, but I don't think there's inherently information about the origin of the objects coming from the remote destination. Of course we could add this --- I had not thought of adding something like a UDID to model objects. That might be the simplest way to solve this. The only other thing I had thought of was to have a separate object identifier (in fact, our app already has this, so it was a simple quick fix), and not to merge in objects from the subscription if the object already exists locally. I think using a UDID is a better fix.
My subscription with Firebase is set up using their observeEventType(_: FEventType, withBlock: (FDataSnapshot) -> Void ) function, which simply sends an FDataSnapshot object to the closure whenever an update occurs. FDataSnapshot, as far as I can tell, doesn't tell me anything about how it came to be or where it came from.
Edit: in case it's helpful, here is where I set up my subscription (Tasks instead of Moods, and I have tweaked the Remote protocol to accommodate this):
func setupTaskSubscription(updateHandler: ([RemoteRecordChange<RemoteTask>]) -> Void) {
tasksReference.observeEventType(.ChildAdded) { (snapshot: FDataSnapshot!) -> Void in
if let contents = snapshot.value as? [String:AnyObject],
let updatedTask = RemoteTask(record: FirebaseRecord(contents: contents, recordID: snapshot.key)) {
updateHandler([.Insert(updatedTask)])
} else {
updateHandler([])
}
}
}
which is invoked in, e.g., my TaskDownloader, like so:
Howdy!
I've really been enjoying the book and the sync codebase, and am building off it for our own project.
I'm building a remote type that uses Firebase instead of CloudKit. One thing I encountered is the following:
nil
remoteIdentifier
until it is successfully uploadedremoteIdentifier
is assigned to the local object created in step (1)Expected result: we should have one object that has been successfully stored in the remote destination
Actual result: we have created two local objects with identical
remoteIdentifier
values, and there is one object at the remote destination.I'm not sure this scenario is possible with the Moody sample app, or with CloudKit at all, because of the way remote push updates work with CloudKit. But with the way I added Firebase subscriptions / push updates, it's definitely happening for me.
Is this a scenario you contemplated or experienced at all during your work on the sample app? Do you have any ideas about how this could be avoided?
The text was updated successfully, but these errors were encountered: