CloudKit在不同的iCloud帐户之间共享数据,但不与所有人共享 [英] CloudKit share Data between different iCloud accounts but not with everyone

查看:235
本文介绍了CloudKit在不同的iCloud帐户之间共享数据,但不与所有人共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我希望通过iCloud与其他iCloud用户共享数据,但不是与全世界共享数据,而是与选定的其他iCloud用户共享数据。

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.

假设用户A希望能够与其他iCloud用户共享字符串,但不能与所有人共享。因此,用户A希望向用户B分享Hello World,但不向用户C分享,而不是用户D。

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.

所以我的应用程序有一个公共数据库和一个记录输入每个人都一样。在该记录类型中,有一个String类型的字段,对每个人来说都是相同的。

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.

现在用户A将记录Hello World保存到iCloud。这就是诀窍:我会在字符串中添加一个像UUID这样的唯一标识符,以便将Hello World1230ABD6-3C61-1234-802E-D866F09AC012上传到iCloud。

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.

现在,用户A需要告诉用户他想要与他的UUID共享数据,因此用户A告诉用户B.现在,用户A的UUID将作为谓词添加到用户B的CK订阅中。

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.

这将允许用户B从用户A获取字符串,但用户C或用户D不会收到CKNotification,因为他们没有用户A的UUID他们的CKSubscription。

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.

这会起作用吗?或者是否有其他设计模式允许通过iCloud与其他iCloud帐户共享/同步,但不能与所有人(公共)共享/同步?

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。我想要共享的数据不敏感,因此不需要非常安全。数据对每个人(公共)都不感兴趣,因此只需要与选定的其他iCloud帐户共享...

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 !

谢谢

推荐答案

有几个如何实现这样的目标。在所有情况下,它归结为:

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


  • 添加一个CKReference字段,该字段将填充您要与之共享的用户的ID 。

  • 确保您的谓词将过滤该ID为您的CKReference字段(与您共享)

存储CKReference的位置和方式取决于您希望如何共享。

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


  • 如果您只想与一个人共享,那么只需将CKReference字段包含在主记录类型中即可。不要像在问题中所述那样将其添加到邮件中。添加一个额外字段。

  • 如果要共享给有限数量的人,则可以在recordType中添加一个字段,该字段是CKReference的列表。

  • 如果你想与一大群人分享,那么你可以添加一个group recordType,它有一个groupID加上一个groupMembers recordType,你将存储所有用户CKReference id的成员那个小组

在所有情况下,解决方案都是安全的。这一切都归结为您在应用中定义的谓词。如果您的某个谓词过滤器不正确,那么有人可能会看到某些不适合他的内容。

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.

EVCloudKitDao 是一个基于CloudKit的聊天应用程序。它正在使用便利库EVCloudKitDao,但共享内容的结构将类似。

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.

这篇关于CloudKit在不同的iCloud帐户之间共享数据,但不与所有人共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆