gpt4 book ai didi

ios - 暂时禁用通用剪贴板

转载 作者:可可西里 更新时间:2023-11-01 05:42:44 25 4
gpt4 key购买 nike

iOS 和 macOS 具有称为通用剪贴板的内置功能,可使用 iCloud 跨设备同步剪贴板的内容。

NSPasteboard.general.clearContents()
NSPasteboard.general.writeObjects("Test 123")

我想在我的 Cocoa 应用程序的通用粘贴板上写一些东西,以便在不与其他 iCloud 设备同步的情况下在应用程序之间共享它。我找不到办法做到这一点。事实上,我认为如果用户不在设置中手动禁用它是不可能的。

文档说:

The general pasteboard, available by way of the general class method, automatically participates with the Universal Clipboard feature in macOS 10.12 and later and in iOS 10.0 and later. There is no macOS API for interacting with this feature. https://developer.apple.com/documentation/appkit/nspasteboard

但也许有解决方法、私有(private) API(我知道没有 App Store)或其他人可能知道的东西。 :)

干杯

最佳答案

是的,通用粘贴板适用于所有应用程序,但 NSPasteboard 可用于创建私有(private)粘贴板。您需要做的就是:

let myPasteboard = NSPasteboard(name: NSPasteboard.Name("mypasteboard"))

可以查看文档here .因此,您可以将粘贴的项目复制到您的私有(private)粘贴板,并且只有在您需要时,您才可以将数据传输到通用粘贴板,并使数据可供所有应用使用。

但是,如果你想阻止通用剪贴板跨设备共享,你所要做的就是:

let generalPasteboard = NSPasteboard.general

// current host only
generalPasteboard.prepareForNewContents(with: .currentHostOnly)
// write here to the pasteboard

关于ios - 暂时禁用通用剪贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56904388/

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