gpt4 book ai didi

objective-c - 使用 NSPerformService API 调用连续性相机服务

转载 作者:行者123 更新时间:2023-12-03 17:09:04 27 4
gpt4 key购买 nike

我正在尝试使用 BOOL NSPerformService(NSString *itemName, NSPasteboard *pboard); 以编程方式调用连续性相机 (Mac OS) 服务API,以便可以在简单的按钮单击后面 Hook 该功能。需要传入的连续性相机服务的名称是什么 itemName参数?

我无法从 com.apple.nsserivcescache.plist 文件中找到服务的名称,但从上下文菜单中,服务的名称是“拍照”和“扫描文档”。我不确定这些名称是否有效,因为它们始终与设备的名称(iPhone | iPad)相关联。

我尝试过的事情。

NSPerformSerice( @"Take Photo", [NSPasteboard generalPasteboard] ); NSPerformSerice( @"<Name of the iPhone> Take Photo", [NSPasteboard generalPasteboard] ); NSPerformSerice( @"<Name of the iPhone>/Take Photo", [NSPasteboard generalPasteboard] );

最佳答案

我写了一篇关于将连续性相机支持添加到您自己的应用程序的简短文章:https://thomas.zoechling.me/journal/2018/10/Continuity.html

您必须实现NSServicesMenuRequestor以指示您可以处理粘贴板中的图像:

override func validRequestor(forSendType sendType: NSPasteboard.PasteboardType?, returnType: NSPasteboard.PasteboardType?) -> Any? {
if let pasteboardType = returnType,
NSImage.imageTypes.contains(pasteboardType.rawValue) {
return self
} else {
return super.validRequestor(forSendType: sendType, returnType: returnType)
}
}

通过实现上述方法,当前第一响应者的菜单(例如按钮的菜单)将自动填充连续性相机菜单项。

该菜单中的项目将启动 CC UI,然后当用户执行捕获时调用 readSelection(from: Pasteboard)
您可以从那里读取粘贴板内容:

func readSelection(from pasteboard: NSPasteboard) -> Bool {
guard pasteboard.canReadItem(withDataConformingToTypes: NSImage.imageTypes) else { return false }
guard let image = NSImage(pasteboard: pasteboard) else { return false }

self.imageView.image = image
return true
}
<小时/>

还应该可以控制 CC 相关菜单项的插入位置。有一个相关的 NSMenuItemImportFromDeviceIdentifier 常量,但我还没有弄清楚如何使用它。 (此 Twitter 线程中的一些上下文:https://twitter.com/weichsel/status/1052980223891972096)

关于objective-c - 使用 NSPerformService API 调用连续性相机服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54085380/

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