From 1ab44176870dbf8eed694db415ba911117b826df Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 7 Apr 2017 09:27:22 -0400 Subject: [PATCH] Fix paste when pasteboard has multiple items. // FREEBIE --- Signal/src/ViewControllers/MessagesViewController.m | 4 +--- Signal/src/ViewControllers/SignalAttachment.swift | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index d51a2e185..11bab16ee 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -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; diff --git a/Signal/src/ViewControllers/SignalAttachment.swift b/Signal/src/ViewControllers/SignalAttachment.swift index 2b2b07fb0..7fd436663 100644 --- a/Signal/src/ViewControllers/SignalAttachment.swift +++ b/Signal/src/ViewControllers/SignalAttachment.swift @@ -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(pasteboardUTITypes[0]) + return pasteboardUTISet.intersection(validInputUTISet).count > 0 + } + // Returns an attachment from the pasteboard, or nil if no attachment // can be found. //