Skip to content
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

Update AVFileType+Extensions.swift #748

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Source/Helpers/Extensions/AVFileType+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
//
// Created by Nik Kov on 23.04.2018.
// Copyright © 2018 Yummypets. All rights reserved.
//
// Updated by isa yeter on 12.06.2022.

import AVFoundation
import MobileCoreServices

extension AVFileType {
/// Fetch and extension for a file from UTI string
var fileExtension: String {
if let ext = UTTypeCopyPreferredTagWithClass(self as CFString,
kUTTagClassFilenameExtension)?.takeRetainedValue() {
return ext as String
if #available(iOS 14.0, *) {
guard let type = UTType(self.rawValue),
let preferredFilenameExtension = type.preferredFilenameExtension
else {
return "None"
}
return preferredFilenameExtension
}
// Fallback on earlier versions
else {
if let ext = UTTypeCopyPreferredTagWithClass(self as CFString, kUTTagClassFilenameExtension)?.takeRetainedValue() {
return ext as String
}
return "None"
}
return "None"
}
}