Fallback to the first type with a valid extension when sharing media and no supported content types can be found

This commit is contained in:
Stefan Ceriu
2025-08-21 14:36:54 +03:00
parent 028cd17fb0
commit 6da6350226
@@ -125,6 +125,18 @@ extension NSItemProvider {
let supportedContentTypes = registeredContentTypes
.filter { isMimeTypeSupported($0.preferredMIMEType) || isIdentifierSupported($0.identifier) }
// If we can't find any supported types try to fallback to the first with
// a valid extension. Return nil otherwise.
guard !supportedContentTypes.isEmpty else {
for type in registeredContentTypes {
if let fileExtension = type.preferredFilenameExtension {
return .init(type: type, fileExtension: fileExtension)
}
}
return nil
}
// Have .jpeg take priority over .heic
if supportedContentTypes.contains(.jpeg) {
guard let fileExtension = preferredFileExtension(for: .jpeg) else {