在应用程序级别删除粘贴板的内容
Removing contents of pasteboard at the app level
我们正在尝试控制应用程序的粘贴板内容。我已经看到了创建自定义文本字段并以这种方式删除功能的方法,但我想知道是否有办法在应用程序级别执行此操作。
我试图利用 applicationWillResignActive、applicationDidenterBackground 和 applicationWillTerminate。有了这些,我认为我可以清除粘贴板内容,然后让这些数据在应用程序之外安全。
我最初的尝试是模仿我从以前的解决方案中看到的可能不再有效的东西。
var pb = self.pasteboard()
pb.setValue("", forPasteboardType: UIPasteboardNameGeneral)
这里的错误是 AppDelegate 没有成员粘贴板
有没有办法让它在应用程序委托中工作,或者我只能更改应用程序中的所有字段?
没有self.pasteboard()
,但是有UIPasteboard.generalPasteboard()
。
改用它。
您可能已经看到以前的答案,其中 self.pasteboard()
returns 是 UIPasteboard
的一个实例,现在在您的应用程序中它没有被处理。所以你试试这个:
let pasteBoard = UIPasteboard()
pasteBoard.setValue("", forPasteboardType: UIPasteboardNameGeneral)
或者,如果您想在所有其他方法中获取 pasteBoard
实例,则只需在 appDelegate
:
中声明一个 lazy var
lazy var pasteBoard = UIPasteboard()
然后在如下任何方法中使用它:
self.pasteBoard.setValue("", forPasteboardType: UIPasteboardNameGeneral)
我们正在尝试控制应用程序的粘贴板内容。我已经看到了创建自定义文本字段并以这种方式删除功能的方法,但我想知道是否有办法在应用程序级别执行此操作。
我试图利用 applicationWillResignActive、applicationDidenterBackground 和 applicationWillTerminate。有了这些,我认为我可以清除粘贴板内容,然后让这些数据在应用程序之外安全。
我最初的尝试是模仿我从以前的解决方案中看到的可能不再有效的东西。
var pb = self.pasteboard()
pb.setValue("", forPasteboardType: UIPasteboardNameGeneral)
这里的错误是 AppDelegate 没有成员粘贴板
有没有办法让它在应用程序委托中工作,或者我只能更改应用程序中的所有字段?
没有self.pasteboard()
,但是有UIPasteboard.generalPasteboard()
。
改用它。
您可能已经看到以前的答案,其中 self.pasteboard()
returns 是 UIPasteboard
的一个实例,现在在您的应用程序中它没有被处理。所以你试试这个:
let pasteBoard = UIPasteboard()
pasteBoard.setValue("", forPasteboardType: UIPasteboardNameGeneral)
或者,如果您想在所有其他方法中获取 pasteBoard
实例,则只需在 appDelegate
:
lazy var
lazy var pasteBoard = UIPasteboard()
然后在如下任何方法中使用它:
self.pasteBoard.setValue("", forPasteboardType: UIPasteboardNameGeneral)