问题描述
|
也许已经过了一个漫长的夜晚,但我无法理解如何检查剪贴板中的字符串
我一直在阅读NSPasteboard文档。
有人可以帮我吗?
解决方法
您需要对stringForType和NSPasteboardTypeString键使用以下方法,以从剪贴板读取字符串值。
- (NSString *)stringForType:(NSString *)dataType
。
NSPasteboard* myPasteboard = [NSPasteboard generalPasteboard];
NSString* myString = [myPasteboard stringForType:NSPasteboardTypeString];
要使用UIPasteBoard在iOS上执行此操作,请使用以下代码:
UIPasteboard *thePasteboard = [UIPasteboard generalPasteboard];
NSString *pasteboardString = thePasteboard.string;
NSLog(@\"%@\",pasteboardString);
, 您可以在下面找到适用于Mac和iOS的Swift 4版本。
苹果电脑
let pasteboard = NSPasteboard.general
let copiedString = pasteboard.string(forType: .string)
的iOS
let pasteboard = UIPasteboard.general
let copiedString = pasteboard.string // might be nil value,is an optional variable