I've figured out what happens here. Here is what we must do after leaving share:
Leave share
Perform sync again (to get new token)!
Check if we received leaved share on step 2 at fetching because CloudKit server 50% chance will not return updated state if you will perform step 2 right after step 1. Looks like server need some short time to process updates from step 1, so we have to run step 2 for example in 2 seconds after step 1 (and anyway check step 3 after that as I have no idea if it can update it's state longer than half a second as usually).
So, I do not allow to accept any shares until step 3 (check if step 2 fetch contains share deletion) succeeded. If it return deleted share, then it's safe to accept this share again and we will get all updates correctly.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: