最近在做类似淘宝口令码的需求,发现个有关UIPasteboard的疑问。先看下面这个方法
#Summary
Returns whether the pasteboard holds data of the specified representation type.
# Discussion
This method works on the first item in the pasteboard. If there are other items, it ignores them. You can use this method when enabling or disabling the Paste menu command.
Starting in iOS 10, you can directly check which data types are present on a pasteboard by using the convenience methods described in [Checking for Data Types on a Pasteboard](apple-reference-documentation://hcPbJVw0Dk).
- (BOOL)containsPasteboardTypes:(NSArray<NSString *> *)pasteboardTypes;
Checking for Data Types on a Pasteboard
上面的文档意思是containsPasteboardTypes
用来判断pasteboard是否持有的数据类型,自iOS10
以后可以使用hasImages、hasStrings
等方法来替代。
然而问题是
当剪切板复制了一张图片,通过hasStrings
判断结果为true
,string内容为图片地址,这里就不举例说明。
此时想判断剪切板内容依然需要通过containsPasteboardTypes
来判断。pasteboardTypes如Uniform Type Identifiers Overview、CoreServices/UTCoreTypes.h
所示.
谢谢~