-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unknown Hint Identifier for Image MIME Types #62
Comments
Thanks for the detailed issue! I'm surprised I didn't notice before that this is supposed to be a UTI. I know that the initial set of UTIs are loaded from a bundle on disk somewhere, though LaunchServices also maintains a dynamic registry of UTIs from apps on the system. I'm not sure if creating a UTI from a MIME type does any XPC past the initial load to access that dynamic registry, though if it does, hopefully it would cache the results for a given MIME type. I'll do a bit of performance testing right now and see what it actually costs to look up UTIs. |
In quick testing on macOS, first time calling If anything, iOS can be presumed to be faster, due to the lack of a central UTI registry beyond the built-in types. This seems fast enough that it's worth keeping. I'll push out a fix for this today. Thanks again! |
This is now published as v4.4.0. |
That's exactly the kind of behavior I was hoping for. Thanks so much for taking a look and for the quick turnaround on the fix! |
On iOS 10 (building with Xcode 10.2), calling the
parseAsImage(scale:)
method to process HTTP requests for remote images causes the following error message to be logged to the console:I can confirm that a similar error message occurs when attempting to load PNG images as well.
Looking at the implementation of this method, I traced the issue to the following line in the private
UIImage
initializer called from that method:According to Apple's documentation,
CGImageSourceCreateWithData
expectskCGImageSourceTypeIdentifierHint
to be a UTI, rather than a MIME type. For example, according to Apple's Image I/O Programming Guide, the correct UTI for a JPEG image would bepublic.jpeg
.One potential fix would be to use
UTTypeCreatePreferredIdentifierForTag
to get the UTI corresponding to the MIME type like so:My one concern with this approach is that I'm unfamiliar with the performance characteristics of
UTTypeCreatePreferredIdentifierForTag
, and don't know if calling this method incurs a static initialization cost to build up the list of supported UTIs (and if so, how often). It'd be unfortunate if the computation to generate the type hint took longer than it would otherwise.If you also share this concern, an alternative approach would be to hardcode the lookup for only the supported MIME types from a list derived from either this table in the docs or by calling
CGImageSourceCopyTypeIdentifiers(_:)
. The downside to this approach is that it is liable to become stale over time, and at the time of writing, the list is actually quite large (primarily because of disparate RAW camera image types):Finally, the null solution would be to simply remove the type hint altogether.
The text was updated successfully, but these errors were encountered: