无法共享CloudKit CKShare记录 [英] Cannot share CloudKit CKShare record

查看:47
本文介绍了无法共享CloudKit CKShare记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中实现云工具包共享,但是,每当我尝试使用 UICloudSharingController 共享项目时,都会遇到一致的错误:

I'm trying to implement cloud kit sharing in my application, however, whenever I try to share an item using a UICloudSharingController I'm getting a consistent error:

向我展示了用于添加人员的初始共享弹出窗口,然后当我选择如何发送邀请(即通过邮件)的选项之一时, UICloudSharingControllerDelegate 返回调用:

I am presented with the initial share popover for adding people, and then when I select one of the options on how I'd like to send the invitation (i.e: by mail), the UICloudSharingControllerDelegate returns calling:

func cloudSharingController(_ csc: UICloudSharingController, failedToSaveShareWithError error: Error)

并引发错误:

CKError 0x170245d60:无效的参数"(12);添加的共享将被保存,但没有其rootRecord(CKRecordID:0x1700343e0; recordName = C9FA0E96-3461-4C9E-AB99-3B342A37A07A,zoneID = PrivateDatabase:__ defaultOwner _)"

我已经在私有云数据库中为zoneId为"PrivateDatabase"的用户创建了一个自定义区域.我已经创建了一个对象并将其成功保存到iCloud,并且该对象已链接到我先前创建的自定义区域.我用来呈现UICloudSharingController的代码如下:

I've already created a custom zone in the private cloud database for the user whose zoneId is "PrivateDatabase". I've created an object and successfully saved it to iCloud and it is linked to the custom zone I previously created. The code I am using to present the UICloudSharingController is as follows:

let object = // A core data representation of a CKRecord //

let share = CKShare(rootRecord: object.record) //record is a CKRecord that is stored with the core data object 
share[CKShareTitleKey] = object.name as? CKRecordValue
share[CKShareThumbnailImageDataKey] = UIImagePNGRepresentation(object.categoryKey.icon()) as? CKRecordValue
share[CKShareTypeKey] = "reverse.domain" as CKRecordValue
share.publicPermission = .readOnly

let sharingController = UICloudSharingController(share: share, container: self.container)
sharingController.delegate = self
sharingController.availablePermissions = [.allowPrivate, .allowReadOnly]
sharingController.popoverPresentationController?.sourceView = sourceView
controller.present(sharingController, animated: true, completion: nil)

我在这里想念什么?

推荐答案

您为UICloudSharingController的实例使用了错误的初始化程序.两个不同的用例两个不同的初始化器.

You are using the wrong initializer for an instance of UICloudSharingController. There are two different initializers for two different use cases.

  • 如果项是第一次共享(尚未共享),则必须使用rootRecord创建一个新的CKShare实例(就像您在代码中所做的一样),但是必须使用此Initializer初始化UICloudSharingController init(preparationHandler:)
  • 如果某个项目已经在共享过程中,那么您必须从iCloud获取现有共享并使用此Initializer init(share:container:)
  • 初始化UICloudSharingController.
  • If an item is shared the first time (not already shared) you have to create a new instance of CKShare with a rootRecord (as you did in your code) but then you have to initialize your UICloudSharingController with this Initializer init(preparationHandler:)
  • If an item is already in a sharing process, then you have to fetch the existing share from iCloud and initialize your UICloudSharingController with this Initializer init(share:container:)

因此,您遇到的错误是,您创建了一个新的CKShare实例,但随后使用了错误的初始化程序.

So, the error in your case is, that you create a new instance of CKShare but then use the wrong initializer.

更多来自Apple的信息

这篇关于无法共享CloudKit CKShare记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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