CloudKit CKShare用户DidAcceptCloudKitShareWith从不在Mac App上触发

编程入门 行业动态 更新时间:2024-10-11 21:31:44
本文介绍了CloudKit CKShare用户DidAcceptCloudKitShareWith从不在Mac App上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在努力在Swift 4的macOS应用中接受 CKShare 。我已经完成以下所有操作:

  • 创建 CKShare 并将其 rootRecord 保存到CloudKit
  • 添加参与者( CKShare.Participant )
  • 我已确认 CKShare 在CloudKit服务器上,我邀请的人可以访问它。这是屏幕截图:

    单击确定使屏幕淡出:

    不是特别有用。 :)执行此操作后,参与者在CloudKit中的状态仍然为已邀请,因此仍未接受该共享。

    当我单击在消息中的共享链接上,显示了这样的弹出窗口: 单击打开后,该应用程序的新副本将显示在扩展坞中,然后该应用突然关闭。崩溃日志指出:

    由于未捕获的异常 CKException而终止应用程序,原因:应用程序缺少必需的权限com.apple。 developer.icloud-services'

    我尝试在Xcode的功能部分中关闭iCloud,然后再打开,但没有任何改变。我知道这种例外情况是不对的,因为我可以正常启动我的应用并全天使用CloudKit。只有 CKShare 会导致此崩溃。

    这真是一团糟。救救我,欧比万·基诺比,你是我唯一的希望。

    解决方案

    是,

    您需要将此添加到您的info.plist。

    < key> CKSharingSupported< / key> ; < true />

    **编辑答复**

    我使用此代码共享,我不手动执行...不确定在OS XI下必须承认这是否是一个选项。我正在使用iOS。

    let share = CKShare(rootRecord:record2S!) share [CKShareTitleKey] =我的下一个共享作为CKRecordValue share.publicPermission = .none 让SharingController = UICloudSharingController(preparationHandler:{(UICloudSharingController,handler: @escaping(CKShare ?, CKContainer ?, Error ?)->无效)在中让ModifyOp = CKModifyRecordsOperation(recordsToSave: [record2S !, share],recordIDsToDelete:nil) ModifyOp.savePolicy = .allKeys ModifyOp。 ModifyRecordsCompletionBlock = {(记录,记录ID,错误)在处理程序中(share,CKContainer.default(),错误)} CKContainer.default()。privateCloudDatabase.add( ModifyOp)}) SharingController.availablePermissions = [.allowReadWrite, .allowP rivate] SharingController.delegate =自我 SharingController.popoverPresentationController?.sourceView = self.view DispatchQueue.main.async { self.present(sharingController,animation:true,完成:nil)}

    这提供了一个活动控制器,您可以在其中选择说出电子邮件并然后发送链接。您可能还想观看此视频,一开始就专注于cloudKit JS。

    也请观看此WWDC视频 developer.apple/videos/play/wwdc2015/710/ 它谈论了Cloudkit JSON API,使用它可以查询终端窗口/简单脚本中共享的内容。几年前使用Dropbox API时,我做了相同的事情。嘿,您甚至可以在代码中使用cloudkit JSON API代替本地调用。

    I am working on accepting a CKShare in a macOS app in Swift 4. I've already done all the following:

    • Create the CKShare and save it with its rootRecord to CloudKit
    • Add a participant (CKShare.Participant)
    • I've confirmed that the CKShare is on the CloudKit server and that the person I invited has access to it. Here's a screenshot: d.pr/i/0sMFQq

    When I click the share link associated with the CKShare, it opens my app, but nothing happens and userDidAcceptCloudKitShareWith doesn't fire.

    func application(_ application: NSApplication, userDidAcceptCloudKitShareWith metadata: CKShareMetadata) { print("Made it!") //<-- This never gets logged :( let shareOperation = CKAcceptSharesOperation(shareMetadatas: [metadata]) shareOperation.qualityOfService = .userInteractive shareOperation.perShareCompletionBlock = {meta, share, error in print("meta \(meta)\nshare \(share)\nerror \(error)") } shareOperation.acceptSharesCompletionBlock = { error in if let error = error{ print("error in accept share completion \(error)") }else{ //Send your user to where they need to go in your app print("successful share:\n\(metadata)") } } CKContainer.default().add(shareOperation) }

    Is there some kind of URL scheme I have to include in my info.plist? Or perhaps a protocol I need to conform to in my NSApplicationDelegate delegate? I can't, for the life of me, figure out what to do. Thanks in advance!

    Update

    I've tried a few more things on this. When I open the share link in a web browser, I see this:

    Clicking OK makes the screen fade away to this:

    Not particularly helpful. :) After doing this, the participant's status in CloudKit is still Invited, so the share still hasn't been accepted.

    When I click on a share link within Messages, I am shown a popup like this: After I click open, a new copy of my app shows up in the dock, then the app suddenly closes. The crash log states:

    Terminating app due to uncaught exception 'CKException', reason: 'The application is missing required entitlement com.apple.developer.icloud-services'

    I've tried turning iCloud off and on again in the Capabilities section of Xcode, but nothing changes. I know this exception can't be right because I can start my app normally and use CloudKit all day long. Only the CKShare causes this crash.

    This is a mess. Save me, Obi-wan Kenobi, you're my only hope.

    解决方案

    Yes,

    You need to add this to your info.plist.

    <key>CKSharingSupported</key> <true/>

    ** EDITED ANSWER **

    I use this code to share, I don't do it manually... not sure if this is an option under OS X I must confess. I am using iOS.

    let share = CKShare(rootRecord: record2S!) share[CKShareTitleKey] = "My Next Share" as CKRecordValue share.publicPermission = .none let sharingController = UICloudSharingController(preparationHandler: {(UICloudSharingController, handler: @escaping (CKShare?, CKContainer?, Error?) -> Void) in let modifyOp = CKModifyRecordsOperation(recordsToSave: [record2S!, share], recordIDsToDelete: nil) modifyOp.savePolicy = .allKeys modifyOp.modifyRecordsCompletionBlock = { (record, recordID, error) in handler(share, CKContainer.default(), error) } CKContainer.default().privateCloudDatabase.add(modifyOp) }) sharingController.availablePermissions = [.allowReadWrite, .allowPrivate] sharingController.delegate = self sharingController.popoverPresentationController?.sourceView = self.view DispatchQueue.main.async { self.present(sharingController, animated:true, completion:nil) }

    This presents an activity controller in which you can choose say email and then send a link. You might also want to watch this video, focus on cloudKit JS right at the beginning.

    Watch this WWDC video too developer.apple/videos/play/wwdc2015/710/ It talks about the cloudkit JSON API, using it you can query what has and what hasn't been shared in a terminal window/simple script perhaps. I did the same when using dropbox API a few years back. Hey you can even use the cloudkit JSON API within your code in place of the native calls.

更多推荐

CloudKit CKShare用户DidAcceptCloudKitShareWith从不在Mac App上触发

本文发布于:2023-11-27 09:40:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   CKShare   CloudKit   App   Mac

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!