drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 132 forks source link

Binary Data gets lost on the receiving device #228

Closed lkzhao closed 7 years ago

lkzhao commented 8 years ago

I have a model named Image which has 3 binary data attributes call full,medium,thumbnail. Everything work except the received image on the other device are nil for all 3 fields. If I don't open the other device, the data is always there and persistent on one device. But once it gets synced onto the other device, the data will end up lost on both devices.

I am not sure what is the best way to debug this. Maybe I am setting it up wrong? I turned on the verbose logging and it seems that the data that ensembles gets are already nil on the receiving device.

Some notes: I also have a parent entity for this Image model called Identifiable which only contains a uniqueIdentifier attribute, I have checked the Allows External Storage and Optional for the three fields. I am also storing the data instead of making it a transformable attribute.

lkzhao commented 8 years ago

I am doing iCloud sync on iOS 9 btw. I will try dropbox and let you know.

lkzhao commented 8 years ago

Just tried dropbox and it failed to send binaryData too.

lkzhao commented 8 years ago

When I save with my managedObjectContext it return a notification with

NSManagedObjectContextDidSaveNotification:NSConcreteNotification 0x1361325b0 {name = NSManagingContextDidSaveChangesNotification; object = <NSManagedObjectContext: 0x134d521c0>; userInfo = {
    inserted = "{(\n    <Footprint.Image: 0x136113390> (entity: Image; id: 0xd000000000180004 <x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Image/p6> ; data: {\n    dateCreated = \"2016-04-15 05:29:15 +0000\";\n    full = <ffd8ffe0 00104a46 49460001 01000048 00480000 ffe1004c 45786966 00004d4d 002a0000 00080002 01120003 00000001 0001>;\n    height = 2048;\n    identifier = \"639DA767-A7B9-425F-8124-1D50870CA4E3\";\n    medium = <ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 0001>;\n    post = \"0xd000000000140002 <x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Post/p5>\";\n    thumbnail = <ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 0001>;\n    width = 2732;\n})\n)}";
}}

Then, I call mergeWithCompletion, which result the following delegate callback being called.

- (void)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble didSaveMergeChangesWithNotification:(NSNotification *)notification

and returns the incorrect data:

NSConcreteNotification 0x1361a6a60 {name = NSManagingContextDidSaveChangesNotification; object = <NSManagedObjectContext: 0x13619a560>; userInfo = {
    updated = "{(\n    <Footprint.Image: 0x136183ec0> (entity: Image; id: 0xd00000000018001c <x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Image/p6> ; data: {\n    dateCreated = \"2016-04-15 05:29:15 +0000\";\n    full = nil;\n    height = 2048;\n    identifier = \"639DA767-A7B9-425F-8124-1D50870CA4E3\";\n    medium = nil;\n    post = \"0xd00000000014001a <x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Post/p5>\";\n    thumbnail = nil;\n    width = 2732;\n}))}";
}}
drewmccormack commented 8 years ago

Is this with Ensembles v1? I guess it would be, right?

Do you set the data to nil in your code somewhere? Sometimes a part of the code that you don’t expect gets triggered during the merge, and you set it to nil.

Are you sure you are using your contexts from the right thread? Eg. main thread. I have seen that cause odd problems like this. Perhaps turn on the new Core Data thread protection in debug and check.

Do you see the images in the cloud? Ie, on a mac, go to ~/Library/Mobile Documents and see if the data is in there. You should find a ‘data’ folder.

Are you sure you have setup your uniqueIdentifiers right? Note that if you have a background saving context, awakeFromInsert is called twice.

Drew

On 15 Apr 2016, at 07:38, Luke Zhao notifications@github.com wrote:

When I save with my managedObjectContext it return a notification with

NSManagedObjectContextDidSaveNotification:NSConcreteNotification 0x1361325b0 {name = NSManagingContextDidSaveChangesNotification; object = ; userInfo = { inserted = "{(\n (entity: Image; id: 0xd000000000180004 x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Image/p6 ; data: {\n dateCreated = \"2016-04-15 05:29:15 +0000\";\n full = ;\n height = 2048;\n identifier = \"639DA767-A7B9-425F-8124-1D50870CA4E3\";\n medium = ;\n post = \"0xd000000000140002 x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Post/p5\";\n thumbnail = ;\n width = 2732;\n})\n)}"; }}

Then, I call mergeWithCompletion, which result the following delegate callback being called.

  • (void)persistentStoreEnsemble:(CDEPersistentStoreEnsemble )ensemble didSaveMergeChangesWithNotification:(NSNotification )notification and returns the incorrect data:

NSConcreteNotification 0x1361a6a60 {name = NSManagingContextDidSaveChangesNotification; object = <NSManagedObjectContext: 0x13619a560>; userInfo = { updated = "{(\n <Footprint.Image: 0x136183ec0> (entity: Image; id: 0xd00000000018001c x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Image/p6 ; data: {\n dateCreated = \"2016-04-15 05:29:15 +0000\";\n full = nil;\n height = 2048;\n identifier = \"639DA767-A7B9-425F-8124-1D50870CA4E3\";\n medium = nil;\n post = \"0xd00000000014001a x-coredata://6B0DE96A-28F6-426B-9CD6-2B1D10BED0EE/Post/p5\";\n thumbnail = nil;\n width = 2732;\n}))}"; }} — You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/drewmccormack/ensembles/issues/228#issuecomment-210294801