12

In my app I want to share data via iCloud with other iCloud users but not with the whole world but with selected other iCloud users.

I thought about a way this could work, but I am not sure if it will work and if I forgot or misunderstood some things.

Let s say User A wants to be able to share a string with other iCloud users but not with everyone. So User A wants to share „Hello World“ to User B but not to user C and not to User D.

So my app has a Public Data Base and a Record Type that is the same for everyone. In that Record Type there is a Field of type String that is also the same for everyone.

Now User A saves the record „Hello World“ to iCloud. And here comes the trick: I would add a unique identifier like UUID to the string so that something like „Hello World1230ABD6-3C61-1234-802E-D866F09AC012“ will be uploaded to iCloud.

Now User A needs to tell the User he wants to share the data with his UUID, so User A tells it to User B. Now the UUID of User A will be added as a Predicate to the CKSubscription of User B.

This will allow User B to fetch the string from User A, but User C or User D won t receive a CKNotification because they don t have the UUID of User A in their CKSubscription.

Is this going to work? Or is there another design pattern that allows sharing/syncing via iCloud with other iCloud accounts but not with everyone (public) ?

P.S. The data I want to share is not sensitive, so it does not need to be really secure. The data just isn t interesting for everyone (public) so it needs to be shared only to selected other iCloud accounts...

I am thankful for any thoughts or tips how to achieve this !

Thanks

2 Answers 2

17

There are a couple of ways to achieve something like this. In all cases it comes down to:

  • Add a CKReference field that will be populated with the ID of the user that you want to share with.
  • Make sure your predicate will filter for that CKReference field where the ID is yours (shared with you)

Where and how you store that CKReference depends on how you want to share.

  • If you only want to share with only one person, then just include that CKReference field into your main recordType. Do not add it to the message as you stated in your question. Add an extra field.
  • If you want to share to a limited number of people, then you could add a field to your recordType which is a list of CKReference.
  • If you want to share with a large group of people, then you could add a group recordType which would have a groupID plus a groupMembers recordType where you would store all user CKReference id's who are member of that group.

In all cases the solution would be secure. It all comes down to the predicates that you define in your app. If one of your predicate filters is incorrect, then it could happen that someone sees something that is not for him.

In the demo app of EVCloudKitDao is a chat application based on CloudKit. It is using the convenience library EVCloudKitDao but the structure of sharing something would be similar.

4
  • Thanks for help! I will have a look at CKReference. One more question: in my case I just have one single string that needs to be synced by User A and User B. It s not that User A and User B need to add new records all the time like new chat entries in the chat app example... it smore like if i would have a core data attribute that both User A and User B can edit and it will be synced at app start... So do i really need references for this then ? Thanks !
    – Kreuzberg
    Commented Jul 28, 2015 at 19:33
  • Both user A and user B need tho know what record they should be monitoring. If you have a mechanism to get the recordID of the concerning record to the other user, then that would be good enough. You can create your own RecordID. You just have to be sure it will be unique. Commented Jul 28, 2015 at 19:57
  • One addition. For the last 2 months there is a bug in CloudKit that will prevent sending update notifications for record changes. Commented Jul 28, 2015 at 19:58
  • Thanks again! Still very confusing to me all this... What i really want to achieve is like core data icloud sync across different icloud accounts...
    – Kreuzberg
    Commented Jul 28, 2015 at 20:23
10

CloudKit Sharing was introduced at WWDC 2016. This allows sharing of private database records between a known set of users, which is what it sounds like you're looking for. ...... There is a great overview in the "What's new in CloudKit" session: https://developer.apple.com/videos/play/wwdc2016/226/

1
  • 2
    20:30 time of that video starts the "Sharing records" portion of the talk
    – Colin M.
    Commented Jun 29, 2017 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.