Merge branch 'charlesmchen/multipleItemsInPasteboard'

This commit is contained in:
Matthew Chen 2017-04-07 12:04:10 -04:00
commit e3fb0c5987
2 changed files with 14 additions and 3 deletions

View File

@ -109,9 +109,7 @@ typedef enum : NSUInteger {
}
- (BOOL)pasteBoardHasPossibleAttachment {
NSSet *pasteboardUTISet = [NSSet setWithArray:[UIPasteboard generalPasteboard].pasteboardTypes];
if ([UIPasteboard generalPasteboard].numberOfItems == 1 &&
[[SignalAttachment validInputUTISet] intersectsSet:pasteboardUTISet]) {
if ([SignalAttachment pasteboardHasPossibleAttachment]) {
// We don't want to load/convert images more than once so we
// only do a cursory validation pass at this time.
return YES;

View File

@ -245,6 +245,19 @@ class SignalAttachment: NSObject {
return SignalAttachment.audioUTISet.contains(dataUTI)
}
public class func pasteboardHasPossibleAttachment() -> Bool {
guard UIPasteboard.general.numberOfItems >= 1 else {
return false
}
// If pasteboard contains multiple items, use only the first.
let itemSet = IndexSet(integer:0)
guard let pasteboardUTITypes = UIPasteboard.general.types(forItemSet:itemSet) else {
return false
}
let pasteboardUTISet = Set<String>(pasteboardUTITypes[0])
return pasteboardUTISet.intersection(validInputUTISet).count > 0
}
// Returns an attachment from the pasteboard, or nil if no attachment
// can be found.
//