Uniform Type Identifiers

RSS for tag

The Uniform Type Identifiers framework provides a collection of common types, and maps them to MIME and file types.

Uniform Type Identifiers Documentation

Posts under Uniform Type Identifiers tag

16 Posts
Sort by:
Post not yet marked as solved
0 Replies
127 Views
I'm working with NSFileProviderReplicatedExtension for macOS app. I want to apply custom badge on files instead of default badges (For example, com.apple.icon-decoration.heart, com.apple.icon-decoration.pinned, .. and so on). I tried to define new UTI in my Info.plist refering this post (-> https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_declare/understand_utis_declare.html) But it doesn't work. Can i define custom badge? If yes, how can i work with this? Please reply.
Posted
by eunjo.
Last updated
.
Post marked as solved
2 Replies
142 Views
I have a file with custom file extension created by another app (not mine). I would like to have my app in the "open with..." menu for this file but I am not able to find out correct UTI for this file extension. I understand that in macOS I can use mdls command and "kMDItemContentType" field to find out UTI but I need some method that works also for iOS. Thank you.
Posted
by m0rlor.
Last updated
.
Post not yet marked as solved
0 Replies
106 Views
On my spreadsheet application, with its own UTI, I wrote a Spotlight importer plugin. It works well, except that Spotlight group the found files as "Other" and not as "Spreadsheet". My UTI conforms to public.spreadsheet. Any idea? Is there a special kMDxxx key/value to set for that in the importer?(see: https://developer.apple.com/library/archive/documentation/CoreServices/Reference/MetadataAttributesRef/Reference/CommonAttrs.html ) Thanks!
Posted Last updated
.
Post not yet marked as solved
4 Replies
3.2k Views
I have the following code: let ciImage = filterAndRender(ciImage: inputImage, doCrop: true)         let outCGImage = ciContext.createCGImage(ciImage, from: ciImage.extent)!         let dest = CGImageDestinationCreateWithURL(output.renderedContentURL as CFURL, kUTTypeJPEG, 1, nil)!         CGImageDestinationAddImage(dest, outCGImage, [kCGImageDestinationLossyCompressionQuality as String:1] as CFDictionary)         CGImageDestinationFinalize(dest) I get the following caution: " 'kUTTypeJPEG' was deprecated in iOS 15.0: Use UTTypeJPEG instead." However, when I substitute 'UTTypeJPEG' as directed, I get this error: "Cannot find 'UTTypeJPEG' in scope" What should I use for kUTTypeJPEG instead? Thanks!
Posted
by Eric.app.
Last updated
.
Post not yet marked as solved
8 Replies
901 Views
I stumbled upon a really peculiar issue while running my application that features both a functionality to create image and video attachments from the user's photos and videos using the PHPicker* API and previewing said attachments using the QuickLook API: Whenever I tap to open a photo (e.g. a JPEG) or a video (e.g. a MP4) using the QuickLook API, on an iPhone 13 15.4 simulator device on Xcode 13.3 on a M1 Macbook Pro host machine, I get a crash with the following call stack: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]' terminating with uncaught exception of type NSException *** First throw call stack: ( 0 CoreFoundation 0x000000011003bd44 __exceptionPreprocess + 242 1 libobjc.A.dylib 0x000000010cd1ea65 objc_exception_throw + 48 2 CoreFoundation 0x00000001100bcf47 _CFThrowFormattedException + 200 3 CoreFoundation 0x00000001100c7417 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5 + 0 4 CoreFoundation 0x00000001100aa827 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 243 5 CoreFoundation 0x000000011003a998 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 49 6 QuickLook 0x0000000110f37636 __49+[QLItem(PreviewInfo) contentTypesToPreviewTypes]_block_invoke + 484 7 libdispatch.dylib 0x000000011b0f5a5b _dispatch_client_callout + 8 8 libdispatch.dylib 0x000000011b0f6f24 _dispatch_once_callout + 66 9 QuickLook 0x0000000110f37450 +[QLItem(PreviewInfo) contentTypesToPreviewTypes] + 46 10 QuickLook 0x0000000110f37d91 -[QLItem(PreviewInfo) _uncachedPreviewItemTypeForContentType:] + 117 11 QuickLook 0x0000000110f382fe -[QLItem(PreviewInfo) _previewItemTypeForType:] + 150 12 QuickLook 0x0000000110f38104 -[QLItem(PreviewInfo) _getPreviewItemType] + 61 13 QuickLook 0x0000000110fbf4d2 -[QLItem previewItemType] + 59 14 QuickLook 0x0000000110f6ed15 +[QLItemFetcherFactory fetcherForPreviewItem:] + 90 15 QuickLook 0x0000000110fbeb9b -[QLItem fetcher] + 44 16 QuickLook 0x0000000110f22880 -[QLPreviewController previewItemAtIndex:withCompletionHandler:] + 153 17 QuickLook 0x0000000110f587a8 __63-[QLPreviewItemStore previewItemAtIndex:withCompletionHandler:]_block_invoke + 262 18 QuickLook 0x0000000110f8c621 QLRunInMainThread + 51 19 QuickLook 0x0000000110f58673 -[QLPreviewItemStore previewItemAtIndex:withCompletionHandler:] + 181 20 QuickLook 0x0000000110f1c89f -[QLPreviewController internalCurrentPreviewItem] + 222 21 QuickLook 0x0000000110f9c140 -[QLPreviewController(Overlay) _actionButton] + 344 22 QuickLook 0x0000000110f9c81c -[QLPreviewController(Overlay) _toolBarButtonsWithTraitCollection:] + 1147 23 QuickLook 0x0000000110f9a2ff -[QLPreviewController(Overlay) _updateOverlayButtonsIfNeededWithTraitCollection:animated:updatedToolbarButtons:] + 129 24 QuickLook 0x0000000110f999a2 -[QLPreviewController(Overlay) updateOverlayAnimated:animatedButtons:forceRefresh:withTraitCollection:] + 152 25 QuickLook 0x0000000110f1c707 -[QLPreviewController _setCurrentPreviewItemIndex:updatePreview:animated:] + 230 26 QuickLook 0x0000000110f22416 -[QLPreviewController reloadData] + 418 27 <MYAPP> 0x0000000102a03293 __53-[MyPreviewController downloadAttachment]_block_invoke_2 + 611 28 libdispatch.dylib 0x000000011b0f4816 _dispatch_call_block_and_release + 12 29 libdispatch.dylib 0x000000011b0f5a5b _dispatch_client_callout + 8 30 libdispatch.dylib 0x000000011b104325 _dispatch_main_queue_drain + 1169 31 libdispatch.dylib 0x000000011b103e86 _dispatch_main_queue_callback_4CF + 31 32 CoreFoundation 0x000000010ffa8261 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 33 CoreFoundation 0x000000010ffa2a56 __CFRunLoopRun + 2761 34 CoreFoundation 0x000000010ffa1a90 CFRunLoopRunSpecific + 562 35 GraphicsServices 0x00000001209c8c8e GSEventRunModal + 139 36 UIKitCore 0x000000013499c90e -[UIApplication _run] + 928 37 UIKitCore 0x00000001349a1569 UIApplicationMain + 101 38 <MYAPP> 0x0000000102970669 main + 233 39 dyld 0x000000010c6c4f21 start_sim + 10 40 ??? 0x00000002041ad51e 0x0 + 8658801950 41 ??? 0x0000000000000003 0x0 + 3 I tried also selecting a photo or a video using the PHPicker* APIs, and although I get back the file, if I try to query the UTType from the file extension using the [UTType typeWithFilenameExtension:] method, I get back a nil result if the extension passed is either a "jpeg" or a "mp4". The above do not happen if I run the same simulator (iPhone 13 15.4 / Xcode 13.3) on an Intel Macbook Pro host machine, or on a real device. Any ideas?
Posted Last updated
.
Post marked as solved
3 Replies
372 Views
Hi, I’m required to identify file content type (e.g. - tell you that a file is in PDF format, even if the user forced its name to end with .docX, .txt, or even removed it altogether. In other words - identify file type by its real contents. I need to do this fast, for lots of files.  I searched in vain through the MacOS different APIs/Frameworks, from LaunchServices, via MDLS, NSWorkspace, NSURL, and NSFileManager — to no avail. These all provide wonderful APIs for identifying file types - but miserably report the file type as “Microsoft Word” if its filename extension has been set to “.doc” or “.docx”, no matter the content. I then found the ‘file’ command-line in Terminal which does EXACTLY what I want, and reports the correct type every time (well maybe it fails somethings, but I haven’t seen it fail once so far.) Reading ‘man file’ I leaned that it examines a file in 3 stages. stat(2) to start with (identifying Unix things like pipes, sockets, symbolic links etc.) then, it works using some 'unix style' thing called “magic number” mechanism, that employs a “compiled magic file” /usr/share/file/magic.mgc containing “binary signatures” or special “magic numbers” at known offsets that allow quick identification of file formats. Tiny hacking into this file using ’strings’ command I found a rather huge list of formats identifiable by MacOS out of the box - plus - according to man page of file , you should be able to add more “magic” files yourself! However, I wouldn't want to spawn a 'file' command process every time I need to identify a file. I'd rather call some code, or framework from within my process. (This process is of high sensitivity - it is an "Endpoint Security Client" and has lots of restrictions. Is there any public API (Cocoa, Unix, Posix, Core-Foundation, anything!) that will use this "Magic" mechanism to tell me the type of a file? Thank you very much.
Posted
by suMac.
Last updated
.
Post not yet marked as solved
1 Replies
314 Views
Hi, I'm looking at the function activityViewController(_:dataTypeIdentifierForActivityType:) in the UIActivityItemSource protocol. The documentation says "For items that are provided as data, returns the UTI for the item." The return type of the function is a String. I don't know what "UTI" means in this context. The data I'm trying to provide is an HTML document (a string containing HTML). I tried returning "text/html", but I don't think this worked. I'm also unsure whether my "itemForActivityType" function ought to be providing the HTML as a String, or perhaps converting it to Data first. The end result I'm seeing is that I can share the HTML document via Mail, and it looks fine, but if I try to air drop it, I get an error that says "Extension request contains input items but the extension point does not specify a set of allowed payload classes." I'd like my app to be able to share the HTML document via Mail or Airdrop. I don't care if it doesn't support sharing to any other services. Thanks, Frank
Posted
by flarosa.
Last updated
.
Post not yet marked as solved
2 Replies
947 Views
(environment: macOS 11.4, Xcode 12.4, iOS simulator 14.4) The below test does not passed when a project's architectures for "Any iOS Simulator SDK" contains X86_64 only. (Open a new project with architectures arm64 passes) import UniformTypeIdentifiers class UTTypeTests: XCTestCase {     func testThatItConvertsFromMIMEType() {         if #available(iOS 14.0, *) {             guard let mp4Type = UTType(mimeType: "video/mp4") else {                 return XCTFail("Could not decode from MIME type.")             }                          XCTAssertEqual(mp4Type, UTType.mpeg4Movie)         } else {         }   } } similar issue happens on deprecated method UTTypeCopyPreferredTagWithClass
Posted
by yiu por.
Last updated
.
Post not yet marked as solved
0 Replies
349 Views
This is a macOS app, while using Image("my file url") in my CoverImageView, I can export a .png file that contains the Image("my file url") view successfully. However, this doesn't happen when I use Image(nsImage: NSImage(data: imageData.imagedata)), the imageData.imagedata is a Data type that will be gotten when I tap a button and get it from a selected picture (I will show it later in my code). When I select an image, it can be seen in my app's View. However, when I save this View(CoverImageView) to a .png file it only contain the blue view, the Mac view is gone!!!! Here is the CoverImageView from which I want to create a .png file struct CoverImageView: View { @EnvironmentObject var imageData: ImageData var body: some View { ZStack { Rectangle() .frame(width: 512, height: 600) .foregroundColor(.blue) Image(nsImage: (NSImage(data: imageData.imagedata) ?? NSImage(byReferencing: URL(fileURLWithPath: "")))) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 512, height: 512) } } } This is the main view PhotoTestView struct PhotoTestView: View { @State private var imageUrl: URL = URL(fileURLWithPath: "") @EnvironmentObject var imageData: ImageData var body: some View { VStack { CoverImageView() Divider() .frame(width: 1024) HStack { Button(action: { if let openURL = ImageProcess().showOpenPanel() { imageUrl = openURL if let codedImages = try? Data(contentsOf: openURL) { imageData.imagedata = codedImages } } }, label: { Image(systemName: "doc.badge.plus") }) Button(action: { ImageProcess().saveImage() }, label: { Image(systemName: "square.and.arrow.down") }) }.padding() } } } The View Extension which will create a png file from a view extension View { func imageRepresentation(rect: CGRect) -&gt; NSBitmapImageRep? { let hosting = NSHostingView(rootView: self) hosting.setFrameSize(rect.size) hosting.setBoundsSize(rect.size) hosting.layout() hosting.layerContentsRedrawPolicy = .onSetNeedsDisplay hosting.setNeedsDisplay(rect) if let imageRepresentation = hosting.bitmapImageRepForCachingDisplay(in: rect) { hosting.cacheDisplay(in: rect, to: imageRepresentation) return imageRepresentation } return nil } func asImage(rect: CGRect) -&gt; NSImage? { if let cgImage = imageRepresentation(rect: rect)?.cgImage { return NSImage(cgImage: cgImage, size: rect.size) } return nil } func asPngData(rect: CGRect) -&gt; Data? { return imageRepresentation(rect: rect)?.representation(using: .png, properties: [:]) } } png File Reader and Save struct ImageProcess { func showOpenPanel() -&gt; URL? { let openPanel = NSOpenPanel() openPanel.allowedContentTypes = [.image] openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canChooseFiles = true let response = openPanel.runModal() return response == .OK ? openPanel.url : nil } func saveURL() -&gt; URL? { let savePanel = NSSavePanel() savePanel.allowedContentTypes = [.png] savePanel.canCreateDirectories = true savePanel.isExtensionHidden = false savePanel.allowsOtherFileTypes = false savePanel.title = "Save your image" savePanel.message = "Choose a folder and a name to store your image." savePanel.nameFieldLabel = "File name:" let response = savePanel.runModal() return response == .OK ? savePanel.url : nil } func saveImage() { let view = CoverImageView().environmentObject(ImageData()) let imageData = view.asPngData(rect: CGRect.init(x: 0, y: 0, width: 1024, height: 768)) if let url = saveURL() { try? imageData!.write(to: url) } // print(imageData) } } Could you help me?
Posted Last updated
.
Post not yet marked as solved
1 Replies
364 Views
Hi I am trying to create a new document type in my Xcode project but the Document Type pane is bugged. I can't see all the fields, can't click on anything where it says 'Click here to add additional document type properties' and the text fields are even being rendered upside down! I first tried on Xcode 13.1, then updated to 13.2.1 Same issue. Computer language set to English. Nothing unusual about my OS. I tried adjusting my screen resolution. Nothing. Mac mini (M1, 2020)
Posted
by mh175.
Last updated
.
Post not yet marked as solved
2 Replies
703 Views
Consider these 3 lines: BOOL conform = [UTTypeJPEG conformsToType:UTTypeJPEG]; BOOL conform2 = [UTTypeJPEG conformsToType:UTTypeImage]; BOOL conform3 = [UTTypePNG conformsToType:UTTypeImage]; In iOS15 running in the simulator, surprisingly for me, they are not all YES, the last 2 are NO. Apple has deprecated the previous kTypeXXX types in iOS14, so I'm trying to fix those deprecations, but I cannot get it to work in iOS15. Is this not working or am I doing something wrong here?
Posted Last updated
.
Post not yet marked as solved
1 Replies
358 Views
My app imports files from a particular open standard that has a published Uniform Type Identifier (UTI). Recently, another mac app store app added some erroneous UTI declarations for files with the standard file extension for that file type. Using yet another app (non-app-store) to save data off in this common open file format, the system picked one of the erroneous UTI's from the app store app, and now my app and another (major gold-standard) app cannot open the file. Running mdls on the file reveals the kMDItemContentType is a wrong value, and of the 6 apps on my machine that can open and save that format, only the app from the store app is declaring the erroneous UTI value the system picked. Changing the file extension to something else and back to the right thing doesn't work. Changing the default app to open the file didn't work. How do I change the system's incorrect inference of the kMDItemContentType? How can my users do so? My app can't open the file (it's grayed-out in the file browser), but it can open other apps with the same file extension (which perhaps had their content-types set before the app store app with the erroneous definitions was updated to include erroneous definitions). Would merely deleting the offending app fix, or are these files permanently unopenable?
Posted Last updated
.
Post not yet marked as solved
1 Replies
414 Views
I created a custom file type for my app as a package. However when I run the app and try to open a file it does not recognize it as the custom file type, but instead as a regular folder. I haven't changed my settings since I first setup the custom type, and only some of these files in Finder are showing properly. Do I need to do something in Xcode to change the rest of the files in Finder?
Posted
by yyjhuj.
Last updated
.