Can’t get NSSharingServicePicker to work for sharing a CKShare

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:

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)

Accepted Reply

Hi! Your code seems correct to me. Can you file a bug with a sysdiagnose? It's possible this is an issue in the system code.

  • Thank you for your reply! I filed FB11893691 with a minimal sample project to reproduce this. Would be awesome if you could find anything!

  • Whatever you did, it worked! The issue is gone in the latest macOS 13.2 Beta. Thank you!

Add a Comment

Replies

Hi! Your code seems correct to me. Can you file a bug with a sysdiagnose? It's possible this is an issue in the system code.

  • Thank you for your reply! I filed FB11893691 with a minimal sample project to reproduce this. Would be awesome if you could find anything!

  • Whatever you did, it worked! The issue is gone in the latest macOS 13.2 Beta. Thank you!

Add a Comment