From d667f6362cd8ea24732fc4e3fe625d599fda06a1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 7 Jun 2021 20:08:46 -0400 Subject: [PATCH] Use UniformTypeIdentifiers framework for everything --- Tusker/Models/CompositionAttachment.swift | 16 ++++++++-------- Tusker/Models/CompositionAttachmentData.swift | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tusker/Models/CompositionAttachment.swift b/Tusker/Models/CompositionAttachment.swift index 0db4c3a7..30c41be3 100644 --- a/Tusker/Models/CompositionAttachment.swift +++ b/Tusker/Models/CompositionAttachment.swift @@ -8,7 +8,7 @@ import Foundation import UIKit -import MobileCoreServices +import UniformTypeIdentifiers final class CompositionAttachment: NSObject, Codable, ObservableObject { static let typeIdentifier = "space.vaccor.Tusker.composition-attachment" @@ -52,10 +52,10 @@ final class CompositionAttachment: NSObject, Codable, ObservableObject { extension CompositionAttachment: Identifiable {} -private let imageType = kUTTypeImage as String -private let mp4Type = kUTTypeMPEG4 as String -private let quickTimeType = kUTTypeQuickTimeMovie as String -private let dataType = kUTTypeData as String +private let imageType = UTType.image.identifier +private let mp4Type = UTType.mpeg4Movie.identifier +private let quickTimeType = UTType.quickTimeMovie.identifier +private let dataType = UTType.data.identifier extension CompositionAttachment: NSItemProviderWriting { static var writableTypeIdentifiersForItemProvider: [String] { @@ -100,11 +100,11 @@ extension CompositionAttachment: NSItemProviderReading { return try PropertyListDecoder().decode(Self.self, from: data) } else if UIImage.readableTypeIdentifiersForItemProvider.contains(typeIdentifier), let image = try? UIImage.object(withItemProviderData: data, typeIdentifier: typeIdentifier) { return CompositionAttachment(data: .image(image)) as! Self - } else if typeIdentifier == mp4Type || typeIdentifier == quickTimeType { + } else if let type = UTType(typeIdentifier), type == .mpeg4Movie || type == .quickTimeMovie { let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) let temporaryFileName = ProcessInfo().globallyUniqueString - let fileExt = UTTypeCopyPreferredTagWithClass(typeIdentifier as CFString, kUTTagClassFilenameExtension)! - let temporaryFileURL = temporaryDirectoryURL.appendingPathComponent(temporaryFileName).appendingPathExtension(fileExt.takeUnretainedValue() as String) + let fileExt = type.preferredFilenameExtension! + let temporaryFileURL = temporaryDirectoryURL.appendingPathComponent(temporaryFileName).appendingPathExtension(fileExt) try data.write(to: temporaryFileURL) return CompositionAttachment(data: .video(temporaryFileURL)) as! Self } else if NSURL.readableTypeIdentifiersForItemProvider.contains(typeIdentifier), let url = try? NSURL.object(withItemProviderData: data, typeIdentifier: typeIdentifier) as URL { diff --git a/Tusker/Models/CompositionAttachmentData.swift b/Tusker/Models/CompositionAttachmentData.swift index 3f5fa6dc..ab11fd68 100644 --- a/Tusker/Models/CompositionAttachmentData.swift +++ b/Tusker/Models/CompositionAttachmentData.swift @@ -8,7 +8,7 @@ import UIKit import Photos -import MobileCoreServices +import UniformTypeIdentifiers import PencilKit enum CompositionAttachmentData { @@ -74,7 +74,7 @@ enum CompositionAttachmentData { data = context.jpegRepresentation(of: image, colorSpace: colorSpace, options: [:])! mimeType = "image/jpeg" } else { - mimeType = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, kUTTagClassMIMEType)!.takeRetainedValue() as String + mimeType = UTType(dataUTI)!.preferredMIMEType! } completion(data, mimeType)