Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper handling of NSUbiquityKeyValueStore updates across devices?

My app stores a single key-value pair in iCloud using NSUbiquityKeyValueStore, an array of objects. The entire array is saved to iCloud when a change is made to any object in the array. This works great as long as each device has an opportunity to pull down the latest update before a change is made locally. Otherwise the local change can get pushed up to iCloud before other devices' latest updates have been pulled down, and those updates get lost across all devices. Is this my app's shortcoming or iCloud's shortcoming, and how can I prevent this scenario from occurring?

like image 742
Michael Mangold Avatar asked Nov 03 '22 11:11

Michael Mangold


1 Answers

Otherwise the local change can get pushed up to iCloud before other devices' latest updates have been pulled down

I ran into a similar issue this week with a project I'm working on. I just made sure that I didn't push anything up to the iCloud server until I received my first update from iCloud. Also, FWIW, I set a fake key-value pair right after initialization so that it updates immediately.

HackyStack's idea of a local flag is also a good solution; if a change comes in you can ask the user if they want to use it or not. (sorta like how Kindle asks if you want to update to the latest page).

like image 85
Mike M Avatar answered Nov 08 '22 09:11

Mike M