parent
5dcdace26f
commit
e48bf65347
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue