Fix “can’t paste GIF from iMessage” issue.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-06-01 12:46:00 -04:00
parent 5dcdace26f
commit e48bf65347
1 changed files with 26 additions and 18 deletions

View File

@ -279,16 +279,6 @@ class SignalAttachment: NSObject {
return MIMETypeUtil.supportedAudioUTITypes()
}
public class var textUTISet: Set<String> {
return [
kUTTypeText as String,
kUTTypePlainText as String,
kUTTypeUTF8PlainText as String,
kUTTypeUTF16PlainText as String,
kUTTypeURL as String
]
}
public var isImage: Bool {
return SignalAttachment.outputImageUTISet.contains(dataUTI)
}
@ -305,10 +295,6 @@ class SignalAttachment: NSObject {
return SignalAttachment.audioUTISet.contains(dataUTI)
}
public var isText: Bool {
return SignalAttachment.textUTISet.contains(dataUTI)
}
public class func pasteboardHasPossibleAttachment() -> Bool {
return UIPasteboard.general.numberOfItems > 0
}
@ -323,12 +309,34 @@ class SignalAttachment: NSObject {
}
let pasteboardUTISet = Set<String>(pasteboardUTITypes[0])
let mediaUTISet = inputImageUTISet.union(animatedImageUTISet.union(videoUTISet.union(audioUTISet)))
if pasteboardUTISet.intersection(mediaUTISet).count > 0 {
// The pasteboard can be populated with multiple UTI types
// with different payloads. iMessage for example will copy
// an animated GIF to the pasteboard with the following UTI
// types:
//
// * "public.url-name"
// * "public.utf8-plain-text"
// * "com.compuserve.gif"
//
// We want to paste the animated GIF itself, not it's name.
//
// In general, our rule is to prefer non-text pasteboard
// contents, so we return true IFF there is a text UTI type
// and there is no non-text UTI type.
var hasTextUTIType = false
var hasNonTextUTIType = false
for utiType in pasteboardUTISet {
Logger.error("\(utiType) is text? \(UTTypeConformsTo(utiType as CFString, kUTTypeText))")
if UTTypeConformsTo(utiType as CFString, kUTTypeText) {
hasTextUTIType = true
} else {
hasNonTextUTIType = true
}
}
if hasNonTextUTIType {
return false
}
return pasteboardUTISet.intersection(textUTISet).count > 0
return hasTextUTIType
}
// Returns an attachment from the pasteboard, or nil if no attachment