parent
bcd487d311
commit
385f31728d
|
@ -136,6 +136,7 @@ extension DraftAttachment {
|
||||||
|
|
||||||
//private let attachmentTypeIdentifier = "space.vaccor.Tusker.composition-attachment"
|
//private let attachmentTypeIdentifier = "space.vaccor.Tusker.composition-attachment"
|
||||||
|
|
||||||
|
private let imageType = UTType.image.identifier
|
||||||
private let jpegType = UTType.jpeg.identifier
|
private let jpegType = UTType.jpeg.identifier
|
||||||
private let pngType = UTType.png.identifier
|
private let pngType = UTType.png.identifier
|
||||||
private let mp4Type = UTType.mpeg4Movie.identifier
|
private let mp4Type = UTType.mpeg4Movie.identifier
|
||||||
|
@ -147,14 +148,26 @@ extension DraftAttachment: NSItemProviderReading {
|
||||||
// todo: is there a better way of handling movies than manually adding all possible UTI types?
|
// todo: is there a better way of handling movies than manually adding all possible UTI types?
|
||||||
// just using kUTTypeMovie doesn't work, because we need the actually type in order to get the file extension
|
// just using kUTTypeMovie doesn't work, because we need the actually type in order to get the file extension
|
||||||
// without the file extension, getting the thumbnail and exporting the video for attachment upload fails
|
// without the file extension, getting the thumbnail and exporting the video for attachment upload fails
|
||||||
[/*typeIdentifier, */gifType, jpegType, pngType, mp4Type, quickTimeType]
|
[/*typeIdentifier, */ gifType, jpegType, pngType, imageType, mp4Type, quickTimeType]
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> DraftAttachment {
|
public static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> DraftAttachment {
|
||||||
|
var data = data
|
||||||
|
var type = UTType(typeIdentifier)!
|
||||||
|
|
||||||
|
// this seems to only occur when the item is a UIImage, rather than just image data,
|
||||||
|
// which seems to only occur when sharing a screenshot directly from the markup screen
|
||||||
|
if type == .image,
|
||||||
|
let image = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIImage.self, from: data),
|
||||||
|
let pngData = image.pngData() {
|
||||||
|
data = pngData
|
||||||
|
type = .png
|
||||||
|
}
|
||||||
|
|
||||||
let attachment = DraftAttachment(entity: DraftsPersistentContainer.shared.persistentStoreCoordinator.managedObjectModel.entitiesByName["DraftAttachment"]!, insertInto: nil)
|
let attachment = DraftAttachment(entity: DraftsPersistentContainer.shared.persistentStoreCoordinator.managedObjectModel.entitiesByName["DraftAttachment"]!, insertInto: nil)
|
||||||
attachment.id = UUID()
|
attachment.id = UUID()
|
||||||
attachment.fileURL = try writeDataToFile(data, id: attachment.id, type: UTType(typeIdentifier)!)
|
attachment.fileURL = try writeDataToFile(data, id: attachment.id, type: type)
|
||||||
attachment.fileType = typeIdentifier
|
attachment.fileType = type.identifier
|
||||||
attachment.attachmentDescription = ""
|
attachment.attachmentDescription = ""
|
||||||
return attachment
|
return attachment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue