How to sync data in widget?
My project has added widget. Without the need to open the app, the data needs to be updated synchronously when the widget is updated, so I created a synchronizer in both the app and the widget, or created a synchronizer in a singleton class to give app and widget use. However, after the widget is synchronized, opening the app and synchronizing the realm in the app will report the following error: *** Terminating app due to uncaught exception 'RLMException', reason: 'Attempting to create an object of type 'GroupMessage' with an existing primary key value 'D2CB7AB4-D505-4568-83D1-CBA8EB28408B'.'
did you figure it out? this is worrisome
Hey, would need more information to possibly look into this. Things like snippets, a description of your flow, a description of how many Realms you're using and where you're storing... Generally it's a bad idea to create more than one synchronizer in your app for the same Realm store –still, not sure if that's what you're even doing.
I also just ran into this with a UUID PK. I'm looking into it.
First off I see that IceCream treats insertions and modifications to the realm db the same: https://github.com/caiyue1993/IceCream/blob/0b6b24a4eddc331361f3123eab48ef116b123161/IceCream/Classes/SyncObject.swift#L136-L149 whereas SyncKit treats them specially. I think this may be a mistake and source of a race condition or similar issue
I've fixed it with defensive coding in my fork, BigSyncKit: https://github.com/lake-of-fire/BigSyncKit/commit/c2d9e1859fe1d3df65c7a41dda76e026cb4a3128
I collapsed .new and .changed into .newOrChanged and then allowed the realm.add to update an existing object at the site of the crash.