如何使用CloudKit的CKShare创建共享? [英] How to create a share with CloudKit's CKShare?

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

问题描述

我正在研究Apple今年发布的新的 CKShare ,对此我有些疑问。我试图按照WWDC的 CloudKit的新功能视频进行操作,但是部分代码在Xcode中不再起作用。

I'm studying the new CKShare that Apple released this year and I have some questions with it. I was trying to follow the WWDC's "What's new in CloudKit" video but part of the code isn't working anymore in Xcode.

我想做的是:用户将输入其姓名和电话,并单击 UIButton 后,将与特定的人共享。这是代码:

What I'm trying to do is: the user will enter his name and phone and after clicking a UIButton, will share with a specific person. Here is the code:

class ViewController: UIViewController, UICloudSharingControllerDelegate {
    @IBOutlet weak var nome: UITextField!
    @IBOutlet weak var telefone: UITextField!
    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func send(_ sender: AnyObject) {
        print("Send button was clicked.\n")

        let elder = CKRecord(recordType: "Elder")
        elder["name"] = self.name.text as CKRecordValue?
        elder["telephone"] = self.telephone.text as CKRecordValue?

        let ckContainer = CKContainer.default()
        let shareRecord = CKShare(rootRecord: elder)

        shareRecord[CKShareTitleKey] = "Elder" as CKRecordValue?

        let shareController = UICloudSharingController(share: shareRecord, container: ckContainer)
        shareController.delegate = self
        shareController.availablePermissions = [.allowReadOnly]
        shareController.popoverPresentationController?.sourceView = self.button

        self.present(shareController, animated: true)
    }

    func cloudSharingController(_ csc: UICloudSharingController, failedToSaveShareWithError error: Error) {
        print("PROBLEM SAVING SHARE")
    }

    func cloudSharingControllerDidSaveShare(_ csc: UICloudSharingController) {
        print("SHARE SAVED")
    }

    func itemTitle(for csc: UICloudSharingController) -> String? {
        return "a"   //don't know what this is for
    }
}

即使出现CloudSharingController,我的应用程序仍在打印问题保存份额。另外,CKRecord elder 也没有出现在CloudKit的仪表板上。

My app keeps printing "PROBLEM SAVING SHARE" even though the CloudSharingController appears. Also, the CKRecord elder isn't appearing in CloudKit's dashboard.

推荐答案

所以,我知道了出了什么问题...我使用的是云工具包为您创建的默认区域,使用CKShare时您无法执行此操作。
您所要做的就是创建一个私人自定义CKZone并将CKRecord和CKShare保存在其中!

So, I figured out what was wrong... I was using the default zone that cloud kit creates for you and you CANNOT do that when using CKShare. All you have to do is create a private custom CKZone and save the CKRecord and CKShare in it!

这篇关于如何使用CloudKit的CKShare创建共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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