Where's the iPhone MIME type database?

后端 未结 4 1763
太阳男子
太阳男子 2020-12-02 10:36

I have a program for the iPhone that is supposed to be doing intelligent things (picking out appropriate icons for file types) given a list of filenames. I\'m looking for t

4条回答
  •  无人及你
    2020-12-02 11:23

    The following function will return the mime-type for a given file extension in Swift 2

    import MobileCoreServices
    
    func mimeTypeFromFileExtension(fileExtension: String) -> String? {
        guard let uti: CFString = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as NSString, nil)?.takeRetainedValue() else {
            return nil
        }
    
        guard let mimeType: CFString = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() else {
            return nil
        }
    
        return mimeType as String
    }
    

提交回复
热议问题