Chris Vasselli
Chris Vasselli

Reputation: 13334

What could cause NSUbiquitousKeyValueStore.synchronize to fail for certain users?

I use NSUbiquitousKeyValueStore to sync preferences between devices in my app. For a small number of my users (on the order of 0.1%), their preferences do not sync between their devices. The values saved to NSUbiquitousKeyValueStore can be read properly until the app terminates, but when launched again the values are gone.

One clue I have found is that if I call synchronize, it returns false for these users. This seems to be the only reliable indication that anything is going wrong. The documentation states that this function will "...return false if an error occurred. For example, this method returns false if an app was not built with the proper entitlement requests." But since this is working for 99.9% of users, it's hard to imagine it's an entitlement request problem.

I am in contact with one user who has this issue, and they report that there is nothing out of the ordinary about the state of their iCloud account, and they are on the latest version of iOS.

I have tried listening for didChangeExternallyNotification and checking for the various possible NSUbiquitousKeyValueStoreChangeReasonKey that indicate things like being out of storage space, and none of them seem to be triggered for these users.

Are there any other known reasons why synchronize might return false, that might help make sense of why these users cannot sync their preferences?

Upvotes: 3

Views: 328

Answers (1)

Chris Vasselli
Chris Vasselli

Reputation: 13334

Two years later, I actually encountered this on one of my own devices and so I have at least one answer - deleting the app's iCloud data via the Settings app.

I can't remember whether I had deleted it from that device or another device, so I'm not sure if that matters. And I haven't been able to reproduce it since, so I'm not sure if there's more to it than just deleting the data. But looking at the system logs on the device, there were errors from the iCloud sync daemon about not being able to find the iCloud container.

Deleting and reinstalling the app did not fix the issue. But restarting the device did make everything go back to normal.

Upvotes: 0

Related Questions