如何解决从nspasteboard获取字符串
| 也许已经过了一个漫长的夜晚,但我无法理解如何检查剪贴板中的字符串 我一直在阅读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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。