这是一个可复制的swift 3.0版本
NotificationCenter.default.addObserver(self, selector: #selector(clipboardChanged),
name: UIPasteboard.changedNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)
此外,如果您想在此事件中获取剪贴板中的文本,
@objc func clipboardChanged(){
let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
print("String is \(theString)")
// Do cool things with the string
}
}
Run Code Online (Sandbox Code Playgroud)
您可以按照此链接中的说明捕获 UIPastedboardChangedNotification:
示例:(不可能使代码正确显示,我粘贴了图像。
将通知添加到 AppDelegate 中的 didFinishLaunchingwithOptions 回调中
添加函数来处理 UIPastedboardChangedNotification 发送给您 AppDelegate 的情况

| 归档时间: |
|
| 查看次数: |
3108 次 |
| 最近记录: |