0

I’m trying to share CKRecords from my app’s CloudKit database using a CKShare from an NSSharingServicePicker, but the picker doesn’t show any sharing services. I’m pretty much doing exactly what the code samples in the WWDC22 video Enhance collaboration experiences with Messages show:

let itemProvider = NSItemProvider()
if let existingShare {
    itemProvider.registerCKShare(existingShare, container: container)
} else {
    itemProvider.registerCKShare(container: container, preparationHandler: {
        return try await createAndSaveNewCKShare()
    })
}

Then, I add some metadata as described in the video:

let activityItem = NSPreviewRepresentingActivityItem(
    item: itemProvider,
    title: "The title",
    imageProvider: nil, // TODO: Quick Look preview image
    iconProvider: .init(object: NSApp.applicationIconImage)
)

Finally, I create the picker and show it:

let picker = NSSharingServicePicker(items: [activityItem])
picker.show(relativeTo: .zero, of: view, preferredEdge: .minY))

What I then get is a sharing service picker that only shows my recent contacts, but not a single sharing service below that. The metadata is there, i.e. the title and app icon show up:

enter image description here

What am I doing wrong here?


I’m pretty confident that most of the code is correct because it works fine on iOS. There, I use the same itemProvider as above, but present the share UI like this, which is pretty much the same:

let configuration = UIActivityItemsConfiguration(itemProviders: [itemProvider])
configuration.perItemMetadataProvider = { _, key in
    switch key {
    case .linkPresentationMetadata:
        let metadata = LPLinkMetadata()
        metadata.title = title
        metadata.imageProvider = nil // TODO: Quick Look preview image
        metadata.iconProvider = nil // TODO: App icon?
    default:
        return nil
    }
}

let viewController = UIActivityViewController(activityItemsConfiguration: configuration)
Marco Masser
  • 1,076
  • 1
  • 8
  • 14

0 Answers0