gpt4 book ai didi

objective-c - 将不同种类的项目共享到 NSSharingServicePicker?

转载 作者:行者123 更新时间:2023-12-05 07:54:52 36 4
gpt4 key购买 nike

假设我想分享一张图片、一些文本和一个任意文件(例如 plist)。

如果我尝试使用 NSSharingServicePicker,它只会显示可以处理所有三种类型 的共享服务。所以它不会显示 Air Drop 因为它不支持文本,它不会因为文件而显示 Twitter 或 Facebook,它不会因为文件和文本而显示 Acorn。

我想提供共享每个服务可用的任何内容(因此 Acorn 将只获取图像,Air Drop 文件和图像,Mail 和 Messages 将获取所有这三者。

有没有办法使用 NSSharingServicePicker 来做到这一点?

我真的不想求助于实现自己的选择器、处理所有共享类型并自己完成所有工作(包括最近的列表和更多...选项)。

最佳答案

您能否使用委托(delegate)回调来扩充服务列表?

您可以使用 sharingServices(forItems: [Any]) -> [NSSharingService] 并通过一次将一种类型传递给多个调用来提前获得对您想要的服务的引用,然后使用委托(delegate)用您的服务列表填充选择器。

我预见的唯一症结(抱歉,没有尝试)是一旦选择了服务,我想知道将传递给它的是哪种类型的项目。

编辑:原始建议:

You might have to use the delegate method func sharingServicePicker(_ sharingServicePicker: NSSharingServicePicker, didChoose service: NSSharingService?) to invoke the service yourself, with the correctdata type, and pass in something to the NSSharingServicePickerinitially which will be sure to fail.

我试图从这个委托(delegate)方法调用服务上的perform,但我在内部发生了崩溃。 :/

/编辑

来自 NSSharingServicePickerDelegate 文档:

func sharingServicePicker(NSSharingServicePicker, sharingServicesForItems: [Any], proposedSharingServices: [NSSharingService]) -> [NSSharingService]

Invoked to allow the delegate to customize exactly what appears in the sharing service picker before it is presented.

The delegate can reorder, remove default services or add customservices before the picker is presented. It's possible to add customservices by mutating the proposedSharingServices array and adding newNSSharingService instances.

The following is an example:

    NSMutableArray *sharingServices = [proposedServices mutableCopy];
NSSharingService * customService = [[[NSSharingService alloc] initWithTitle:@"Service Title"
image:image alternateImage:alternateImage
handler:^{
[self doCustomServiceWithItems:items];
}] autorelease];
[sharingServices addObject:customService];
return [sharingServices autorelease];

Availability

macOS 10.8+

关于objective-c - 将不同种类的项目共享到 NSSharingServicePicker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30881286/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com