Răsfoiți Sursa

extend NSData to act as NSItemProvider for all currently supported mime types/kUTT's

cyberta 2 ani în urmă
părinte
comite
2e869a7945
1 a modificat fișierele cu 21 adăugiri și 0 ștergeri
  1. 21 0
      deltachat-ios/Extensions/Extensions.swift

+ 21 - 0
deltachat-ios/Extensions/Extensions.swift

@@ -1,6 +1,8 @@
 import UIKit
 import Foundation
 import CommonCrypto
+import UniformTypeIdentifiers
+import MobileCoreServices
 
 extension Dictionary {
     func percentEscaped() -> String {
@@ -142,3 +144,22 @@ extension NSData {
          return hexBytes.joined()
     }
 }
+
+extension NSData: NSItemProviderReading {
+    public static var readableTypeIdentifiersForItemProvider: [String] {
+        return [kUTTypePDF as String,
+                kUTTypeText as String,
+                kUTTypeRTF as String,
+                kUTTypeSpreadsheet as String,
+                kUTTypeVCard as String,
+                kUTTypeZipArchive as String,
+                kUTTypeImage as String,
+                kUTTypeMovie as String,
+                kUTTypeVideo as String,
+                kUTTypeData as String]
+    }
+
+    public static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> Self {
+        return NSData(data: data) as! Self
+    }
+}