有没有办法检查应用程序将接受哪些粘贴板项目?

Is there a way to check what pasteboard items an application will accept?

根据我对粘贴板工作原理的理解,当发出粘贴请求时,请求者还会指出它允许的数据类型。有没有办法在发出粘贴请求之前获取有关应用程序的信息?

检查 NSPasteboardReading 和 NSPasteboardWriting 协议文档。

// writableTypesForPasteboard: - Returns an array of UTI strings of data types the receiver can write to a given pasteboard

- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard

// readableTypesForPasteboard : - Returns an array of UTI strings of data types the receiver can read from the pasteboard and be initialized from

+ (NSArray *)readableTypesForPasteboard:(NSPasteboard *)pasteboard

如果您需要更多详细信息,建议阅读 "Pasteboard Programming Guide":https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/PasteboardGuide106/Introduction/Introduction.html

不,您无法获得有关应用程序可以处理哪些粘贴板类型的信息。

执行粘贴操作的应用程序没有准确地告诉系统它接受什么数据类型。它根据某些类型过滤接收到的数据类型列表。但是,它可以使用动态信息执行此操作,并且每次可以使用不同的数据类型集进行多次过滤。

粘贴板的API非常灵活。在一些高级方法中,应用程序会提供它可以处理的类型列表(或者可能 类)并取回相关项(或对象)。但是,还有一些低级方法,应用程序可以通过这些方法枚举所有项目及其类型,并根据它喜欢的任何逻辑选择一个。它可能永远不会将 types/classes 的列表传递到框架中。即使它确实将 types/classes 的列表传递到框架中,该列表也会在应用程序内部处理。它不会与更广泛的系统共享,因为没有理由这样做。而且,如前所述,它可以是一个动态列表。