I am new fairly new to swift development but am obsessed and in love with learning, I have not only dedicated myself to learning but I am starting to apply my knowledge and have built a small messaging app with the capability to select a file. I have successfully created the ability for future users of my app to send documents via the messaging system, and I am able to show the file name, type etc. However, I am struggling to understand (reading apple documentation and other community developer's posts regarding this) how to fetch a specific icon type from the iOS system based on the file's extension type (e.g. xlsx), let alone the UTIType (e.g. public.movie -> mp4, etc.).
If anyone has suggestions on how/where to facilitate this, I would like to set my current, generic file icon to a custom filetype, as the one in the attached image example below (PDF in example):
Tarun's answer was quick and very helpful in getting one step further, however, it returned this icon for pdf, png, and jpeg, all tested (regardless of the aforementioned differentiation in file type.
Here is my code:
guard let fileUrl = message.documentUrl else { return }
let fileNameUrl = (fileUrl as NSString).lastPathComponent
let fileName = fileNameUrl.components(separatedBy: "?")[0].removingPercentEncoding
let documentInteractionController = UIDocumentInteractionController()
documentInteractionController.name = fileName
documentInteractionController.url = URL(fileURLWithPath: fileNameUrl)
let fileTypeIcon = documentInteractionController.icons.first
fileIcon.image = fileTypeIcon