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

20 Posts
Sort by:
Post not yet marked as solved
3 Replies
490 Views
Hello, I'm wondering if there is a way to programmatically write a series of UIImages into an APNG, similar to what the code below does for GIFs (credit: https://github.com/AFathi/ARVideoKit/tree/swift_5). I've tried implementing a similar solution but it doesn't seem to work. My code is included below I've also done a lot of searching and have found lots of code for displaying APNGs, but have had no luck with code for writing them. Any hints or pointers would be appreciated. func generate(gif images: [UIImage], with delay: Float, loop count: Int = 0, _ finished: ((_ status: Bool, _ path: URL?) -> Void)? = nil) { currentGIFPath = newGIFPath gifQueue.async { let gifSettings = [kCGImagePropertyGIFDictionary as String : [kCGImagePropertyGIFLoopCount as String : count]] let imageSettings = [kCGImagePropertyGIFDictionary as String : [kCGImagePropertyGIFDelayTime as String : delay]] guard let path = self.currentGIFPath else { return } guard let destination = CGImageDestinationCreateWithURL(path as CFURL, __UTTypeGIF as! CFString, images.count, nil) else { finished?(false, nil); return } //logAR.message("\(destination)") CGImageDestinationSetProperties(destination, gifSettings as CFDictionary) for image in images { if let imageRef = image.cgImage { CGImageDestinationAddImage(destination, imageRef, imageSettings as CFDictionary) } } if !CGImageDestinationFinalize(destination) { finished?(false, nil); return } else { finished?(true, path) } } } My adaptation of the above code for APNGs (doesn't work; outputs empty file): func generateAPNG(images: [UIImage], delay: Float, count: Int = 0) { let apngSettings = [kCGImagePropertyPNGDictionary as String : [kCGImagePropertyAPNGLoopCount as String : count]] let imageSettings = [kCGImagePropertyPNGDictionary as String : [kCGImagePropertyAPNGDelayTime as String : delay]] guard let destination = CGImageDestinationCreateWithURL(outputURL as CFURL, UTType.png.identifier as CFString, images.count, nil) else { fatalError("Failed") } CGImageDestinationSetProperties(destination, apngSettings as CFDictionary) for image in images { if let imageRef = image.cgImage { CGImageDestinationAddImage(destination, imageRef, imageSettings as CFDictionary) } } }
Posted
by wmk.
Last updated
.
Post marked as solved
3 Replies
236 Views
Hello! I've been trying to create a custom USDZ viewer using the Vision Pro. Basically, I want to be able to load in a file and have a custom control system I can use to transform, playback animations, etc. I'm getting stuck right at the starting line however. As far as I can tell, the only way to access the file system through SwiftUI is to use the DocumentGroup struct to bring up the view. This requires implementing a file type through the FileDocument protocol. All of the resources I'm finding use text files as their example, so I'm unsure of how to implement USDZ files. Here is the FileDocument I've built so far: import SwiftUI import UniformTypeIdentifiers import RealityKit struct CoreUsdzFile: FileDocument { // we only support .usdz files static var readableContentTypes = [UTType.usdz] // make empty by default var content: ModelEntity = .init() // initializer to create new, empty usdz files init(initialContent: ModelEntity = .init()){ content = initialContent } // import or read file init(configuration: ReadConfiguration) throws { if let data = configuration.file.regularFileContents { // convert file content to ModelEntity? content = ModelEntity.init(mesh: data) } else { throw CocoaError(.fileReadCorruptFile) } } // save file wrapper func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { let data = Data(content) return FileWrapper(regularFileWithContents: data) } } My errors are on conversion of the file data into a ModelEntity and the reverse. I'm not sure if ModelEntity is the correct typing here, but as far as I can tell .usdz files are imported as ModelEntities. Any help is much appreciated! Dylan
Posted
by dganim8s.
Last updated
.
Post not yet marked as solved
0 Replies
123 Views
I'm developing an application that is supposed: to open .3mf file (and other file types), and to provide Quick Look thumbnails for this file format. Because of (2) I need to add UTIs into my app Info.plist (and to my thumbnailing appex Info.plist). So the app's Info.plist changes are: into CFBundleDocumentTypes key of 3mf file type adding my custom UTI like this: <key>LSItemContentTypes</key> <array> <string>com.prusa3d.slic3r.3mf</string> </array> Creating UTExportedTypeDeclarations section with UTI metadata for given file type like this: <key>UTExportedTypeDeclarations</key> <array> ... <dict> <key>UTTypeIdentifier</key> <string>com.prusa3d.slic3r.3mf</string> <key>UTTypeConformsTo</key> <array> <string>public.zip-archive</string> </array> <key>UTTypeDescription</key> <string>3MF</string> <key>UTTypeIcons</key> <dict/> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>3mf</string> </array> </dict> </dict> ... </array> Unfortunately this is not working as I've installed Shapr3D app, which registers the same file extension with own different UTI ID like this: <key>UTImportedTypeDeclarations</key> <array> ... <dict> <key>UTTypeConformsTo</key> <array> <string>public.data</string> </array> <key>UTTypeDescription</key> <string>3MF</string> <key>UTTypeIconFiles</key> <array> <string>document-icon-64x64.png</string> <string>document-icon-320x320.png</string> </array> <key>UTTypeIdentifier</key> <string>com.shapr3d.3d-manufacturing.3mf</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <string>3mf</string> </dict> </dict> ... </array> So my question is: How can I handle this UTI ID/file extension conflict? So far I came up with following bad but working solution: Uninstall the conflicting application, Use the same UTI ID. I say "bad solutions" because: The (1) is user hostile/unacceptable approach, the (2) is fragile approach, as there are other applications that may register same file extension with different UTI ID (the .3mf sort of universal file format for 3D manufacturing the other apps are using too).
Posted
by rzo.
Last updated
.
Post not yet marked as solved
0 Replies
197 Views
I'm struggling to create a simple document app on macOS that can open a directory (and display content found there). I created a new project in Xcode 15 using the "Document App" template and then just changed the readableContentTypes var like this: struct DocumentDemoDocument: FileDocument { //... static var readableContentTypes: [UTType] { [.directory, .folder] }``` //... } But, when I run that app and choose File->Open..., the Open button is still grayed out when a directory is selected. What did I miss here?
Posted
by dabx.
Last updated
.
Post marked as solved
3 Replies
270 Views
For the fields listed below, what are the recommended or typical values such that (1) my app can open, edit, and save any ".txt" file and (2) such that other text viewing/editing apps can open the files created by my app? If it matters, my app can view, create, edit, and save UTF-8 text. Document Types fields Name and Types and all the fields for Imported Type Identifiers. And any other important fields or other things that I should set. Also, if I upload my app to the App Store and make a mistake on some or all of these, will I be able to correct them? My knowledge in this area is close to zero, so I'm hoping for minimal technical information, just simple answers if such are possible. I hope you understand.
Posted
by abrevi1.
Last updated
.
Post not yet marked as solved
0 Replies
351 Views
Hi and thank you in advance for the support. I’m working on a project that allows users to drag and drop files into and out of my app using the Drag and Drop API. From my understanding, dropping a file into the app requires the file to be an NSItemProvider to be eligible for a drop - like this: func onDrop(of: [UTType], is Targeted: Binding&lt;Bool&gt;?, perform: ([NSItemProvider]) -&gt; Bool) -&gt; some View and dragging a file out of the app requires the same: func onDrag (() -&gt; NSItemProvider) -&gt; some View The only success I’ve had with this is actually specifying the subtype of NSItemProvider the app will be receiving via drop, or dragging away - like this: /*Example view with drop modifier*/ ScrollView { Text(“Dropped text”) .onDrag { handleDragAway(for: text) } } .onDrop(of: [UTType.text.identifier], isTargeted: nil) { providers in handleDrop(providers: providers) } /*Handle drop of item NSItemProvider conforming to plain text*/ func handleDropInto(providers: [NSItemProvider]) -&gt; Bool { var didHandle = false for provider in providers { if provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) { _ = provider.loadObject(ofClass: String.self) { string, _ in DispatchQueue.main.async { if let string = string { self.handlePlainText(text: string) didHandle = true } } } } else { didHandle = false } return didHandle } } /*Handle dragging the item away*/ func handleDragAway(for text: String) -&gt; NSItemProvider { return NSItemProvider(object: text as NSString) } Essentially this code, albeit incomplete, gets the idea across. Drag text into the view, display the text, drag it out. Now, all the documentation I can find says you can rinse and repeat for basically any file type (with some processing) that conforms to NSItemProvider. Here is my question: what if I don’t want to specify file type - what if I just want to tell the app, the user is dragging in some file that conforms to NSItemProvider, don’t worry about its type. Display “File” to show the user they have successfully dropped a file into the view, but don’t do any with the file (this could be implemented later). Then, the user can drag that file away, conforming to NSItemProvider, and wherever they drag it can deal with its file type. Here is an implementation of this idea: import SwiftUI import UniformTypeIdentifiers struct BoardItem { let id: UUID let provider: NSItemProvider } struct BoardItemView: View { var body: some View { Text("File") .frame(width: 100, height: 100) .border(Color.black) } } struct BoardView: View { @State private var boardItems: [BoardItem] = [] var body: some View { ScrollView { ForEach(boardItems, id: \.id) { item in BoardItemView() .onDrag { return item.provider } } } .onDrop(of: [UTType.item.identifier], isTargeted: nil) { providers in providers.forEach { provider in let newItem = BoardItem(id: UUID(), provider: provider) DispatchQueue.main.async { boardItems.append(newItem) } } return true } .frame(maxWidth: .infinity, maxHeight: .infinity) } } The code compiles and runs easily on iPadOS or visionOS. The user can drop anything into the view, “File” appears on screen, and the user can even grab the text (that represents the file). However, dragging the object into a new app does not work. There is no green “+” element to verify the object is droppable anywhere, and attempting to drop it anywhere results in a red console message in Xcode saying Cannot retrieve a strong reference to PBItemCollection. Does anyone know how to fix the functionality and the error? I appreciate you engaging in a long post, thank you!
Posted
by jklawlor.
Last updated
.
Post not yet marked as solved
2 Replies
329 Views
Hi, I am working on an iOS app that has a custom document type that can be shared with other devices through Airdrop, iMessages, etc. The app should appear in the "Open In..." menu upon receiving the file however, currently it gets directed straight to the files app. I got this feature to work in a previous iteration of the app in iOS 16 but it no longer works with iOS 17. The feature is also broken with the previous iteration in iOS 17. I have defined the custom document type under both Documents Type and Exported Type Identifiers. I have attached a copy of the info.plist below. My question is how can you make your app appear under the list of apps shown in the "Open In..." menu that appears when receiving files for a custom file type. <plist version="1.0"> <dict> <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeIconSystemGenerated</key> <integer>1</integer> <key>CFBundleTypeName</key> <string>RecordingList</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>LSHandlerRank</key> <string>Owner</string> <key>LSItemContentTypes</key> <array> <string>com.nikodittmar.MyRaceTimer.recordinglist</string> </array> </dict> </array> <key>UTExportedTypeDeclarations</key> <array> <dict> <key>UTTypeConformsTo</key> <array> <string>public.data</string> </array> <key>UTTypeDescription</key> <string>RecordingList</string> <key>UTTypeIcons</key> <dict/> <key>UTTypeIdentifier</key> <string>com.nikodittmar.MyRaceTimer.recordinglist</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>recordinglist</string> </array> </dict> </dict> </array> <key>UTImportedTypeDeclarations</key> <array> <dict> <key>UTTypeConformsTo</key> <array> <string>public.plain-text</string> </array> <key>UTTypeDescription</key> <string>CSV</string> <key>UTTypeIcons</key> <dict/> <key>UTTypeIdentifier</key> <string>public.comma-separated-values-text</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>csv</string> </array> <key>public.mime-type</key> <array> <string>text/csv</string> </array> </dict> </dict> </array> </dict> </plist> import UniformTypeIdentifiers extension UTType { static var recordingList: UTType { UTType(exportedAs: "com.nikodittmar.MyRaceTimer.recordinglist") } } Thanks.
Posted Last updated
.
Post marked as solved
2 Replies
316 Views
Per the docs, NSImage.imageTypes returns a list UTI's, something like below: com.adobe.pdf com.apple.pict com.adobe.encapsulated-postscript public.jpeg public.png com.compuserve.gif com.canon.tif-raw-image ... What I need is get file extensions of a UTI. For example, public.jpeg picture file may have several file extensions, say .jpg,.jpeg,.jfif. Does Cocoa provide any API to query for this information?
Posted
by imneo.
Last updated
.
Post not yet marked as solved
2 Replies
496 Views
Updating to MacOS 12, in Objective C, I get the above warning regarding changing kUTTypeJPEG to UTTypeJPEG in two places The old code still works but even after the @import UniformTypeIdentifiers changing kUTTypeJPEG to UTTypeJPEG with various types, e.g. CFString, CFStringRef, and that UTTYPE doesn't bridge???, etc. (I am obviously clueless about this) I get the compiler warnings to go away but then the program crashes. How do I fix these? Something to do with ARC or bridging??? CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)theURL, (NSString *)kUTTypeJPEG, 1, NULL); NSDictionary *imageSourceCreationOptions = [NSDictionary dictionaryWithObjectsAndKeys: kUTTypeJPEG,(NSString *)kCGImageSourceTypeIdentifierHint, (NSNumber *)kCFBooleanTrue, (NSString *)kCGImageSourceShouldCache, (NSNumber *)kCFBooleanTrue, (NSString *)kCGImageSourceShouldAllowFloat, nil];
Posted
by DrMiller.
Last updated
.
Post not yet marked as solved
2 Replies
415 Views
I cannot define my application defined type files like .AAA and .BBB and I can air drop multiple .AAA files or multiple .BBB files to my iPhone and use my application to received these files. but if I mix .AAA and .BBB files and air drop them to my phone. My phone always prompts " cannot receive all these items at once. So, how to receive a mix of my application defined type files through air drop? thanks
Posted Last updated
.
Post marked as solved
3 Replies
483 Views
I've created a library that defines an encoded reference type, and was in the process of adding Transferrable conformance to the main class that represents the data. Doing so wants a type defined for the transferrable, so I'm adding a type for this data representation into the library. The extension on UniformTypeIdentifiers is trivial, but I'd like to also mark that the type itself conforms to public.data (UTType.data). Since this is in a swift package, there isn't an application-relevant Info.plist that would normally hold these additional details. Can I add the conformance through the library? Or is the whole aspect of Transferrable and associated UTTypes expected to be something only defined at the application level?
Posted
by heckj.
Last updated
.
Post not yet marked as solved
2 Replies
1.1k Views
Dear Experts, I'm attempting to make a custom icon appear in the iOS Files app, etc., for my file type. I've found a couple of bits of documentation for Info.plist keys: https://developer.apple.com/documentation/bundleresources/information_property_list/utexportedtypedeclarations/uttypeiconfiles describes UTTypeIconFiles, to be included in UTImportedTypeDeclarations. This documentation is very sparse! Older document https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9 describes CFBundleTypeIconFiles, to be included in CFBundleDocumentTypes. Which of these should I be using? (Both? Neither?) Nothing I've tried so far has worked. I wonder if I need to, for example, power-cycle to make the Files app pick up the new icons. Also, in Xcode, I've found the Imported Type Identifiers section of the Info settings which has a box labelled "Add imported type identifiers here" - but clicking + and choosing a file does nothing; the box remains empty. Anyone else have that problem? What size should the icons be? The older document suggests some rather small sizes, e.g. 22x29; the newer doc says nothing. Suggestions anyone?
Posted
by endecotp.
Last updated
.
Post not yet marked as solved
0 Replies
744 Views
Hi, My iOS app used to import say abc.xyz file using ‘Open in App’ option which is achieved using Uniform Type Identifiers(UTI). This abc.xyz file was attached and shared via an email client. [Note: My app also has Share extension to import other file type] Upto iOS 15, When I try to import this file to my app I can see 2 options(Expected behaviour): Open in app Share with app But from iOS 16 and above(latest iOS 17 beta 4), I can only see below option, Share with app To debug further, I created a project(iOS 17 beta 4) and added UTI support for abc.xyz file format(Same as above). When the same file is attached in email client and try to import to app, I can see below option, Copy to app When this file is saved locally(on device) and later try to import from the Files folder, I can see below option, Open in app But the moment I add Share extension(Which is the requirement of my app), the only option to import file is Share with app From the above observation my queries are, Why there is behavioural change from iOS 16 and above when showing the options to import file ? Has “Open in app” option removed when Share extension is present in app from iOS 16 and above ? Does that mean when Share extension target is added in project the only way to import files is via Share extension from iOS 16 and above ? Or can you please suggest if any extra parameters to be added to info.plist from iOS 16 and above to support both options i.e., Open in app & Share with app ?
Posted
by BMDivya.
Last updated
.
Post not yet marked as solved
0 Replies
755 Views
Hello there, I would like to bring attention to an issue I'm facing with SwiftData while attempting to create my own document type and a document-based app. It appears that there is a lack of support for imported types, and I'm unsure if this is a result of the beta version or an intentional omission. To reproduce the problem, please follow these steps: Create a document-based app with SwiftData enabled. Define your document type as "test" in the info.plist file. Include the "test" type in the list of exported type identifiers. Add a commonly used type such as "pdf" or "txt" to the list of imported type identifiers. Within the app's body, include a DocumentGroup with the content type set as "test." Currently, the app is capable of opening and creating new documents with the "test" type. However, I am unable to open common file types, such as images or text files. This limitation is a significant concern since the app often needs to handle these general file formats rather than being limited to its specific format. Thank you for your attention to this matter. I appreciate any assistance you can provide in resolving this issue. Best regards, Jeremy Vizzini
Posted Last updated
.
Post marked as solved
1 Replies
614 Views
I have an API endpoint that returns array of various items, so I have created an enum that can hold those items and therefore I can create an array of them - more less like below let arr: [CollectableEnum] = [ .feed(.init(id: "1")), .clinic(.init(id: "1")), .feed(.init(id: "2")), ] Now I need to iterate through them and display properly in SwiftUI I wonder, how to get an value from that enum, so I can get an ItemModel rather than CollectableEnum that holds that ItemModel enum code: enum CollectableEnum: Identifiable, Hashable { case feed(ItemModel) case clinic(ClinicModel) var id: String { switch self { case .feed(let feed): return feed.id case .clinic(let clinic): return clinic.id } } // what return type should I put here? var associatedValue { switch self { case .feed(let feed): return feed case .clinic(let clinic): return clinic } } public func hash(into hasher: inout Hasher) { return hasher.combine(self) } }
Posted
by breq.
Last updated
.
Post not yet marked as solved
5 Replies
8.6k 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 marked as solved
3 Replies
1.2k Views
I am attempting to add an exported type identifier for a file type my app will be using. However, in Xcode 14.3, I am trying to add additional properties, the "Click here to additional exported type identifier properties" zone does nothing. I also cannot find a way to remove any type identifiers if I accidentally add too many. There is only a plus button, no minus button. What step am I missing here?
Posted
by jerdrb.
Last updated
.
Post marked as solved
8 Replies
4.8k Views
On iOS:When one receives a file of type .pages by email, Mail displays a large Pages icon and tapping on it opens Pages. (A long-press brings up the more complicated Actions screen).When one receives a file of type .vcf by email, Mail displays a large Contacts icon and tapping on it opens Contacts. (A long-press brings up the more complicated Actions screen).I have my own custom file type, .ripf, and I want to have the same behaviour because that is what my users will expect. Accordingly, in my app's Info.plist I have a CFBundleDocumentTypes dictionary providing a one-element LSItemContentTypes array referring to the name 'com.universalis.ripcard', and a UTExportedTypeDeclarations dictionary associating the UTTypeIdentifier 'com.universalis.ripcard' with a public.filename-extension 'ripf' and a public.mime-type 'text/vnd.universalis.ripcard'. All the other entries in those two dictionaries are present and correct as far as I can tell. Both CFBundleDocumentTypes[0].CFBundleTypeIconFiles and UTExportedTypeDeclarations[0].UTTypeIconFiles contain a list of icon files for the file type.(That rather long paragraph is to avoid boring people by including the entire Info.plist!)Some things do work..ripf files received via AirDrop bring up a suitable "Open with..." message which mentions my app, and tapping the message opens the app..ripf files received as an email attachment display as an icon. But it is the app's icon and not the icon of the file type.BUTTapping on a received file's icon does not open the app, but only opens the generic Actions screen, offering Message, Mail, WhatsApp, Notes, and only then (after the user has scrolled sideways) "Copy to..." my app.Now, the whole apparatus of CFBundleDocumentTypes and UTExportedTypeDeclarations is obscure and under-documented, and indeed the main documenation for the latter has a big warning at the top saying that it is obsolete and not being updated. That doesn't matter so much. What I need to know is:(Less important): How do I get the right file icon?(More important): How do I get my app to open when the icon is tapped, as Pages and Contacts do? There must be a way – unless special cases for those two apps are wired into iOS itself.
Posted Last updated
.