通过文件后缀判断属于那种UTI类型

涉及的核心知识点

参考大神文章

传送门1:https://blog.csdn.net/heroguo_jp/article/details/51134308

传送门2:https://www.cnblogs.com/haibosoft/p/4180587.html

涉及的核心类库

#import <MobileCoreServices/MobileCoreServices.h>

代码实现

NSString *fileExtension = [fileURL pathExtension];
NSString *fileUTI = [self preferredUTIForExtention:fileExtension];

if (UTTypeConformsTo(CFBridgingRetain(fileUTI), kUTTypeImage)) {
    NSLog(@"png file");
}

....
  
-(NSString *)preferredUTIForExtention:(NSString *)ext {
    //Request the UTI via the file extension
    NSString *theUTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)(ext), NULL);
    return theUTI;
}
posted @ 2020-01-13 14:27  大卫的梦呓  阅读(227)  评论(0编辑  收藏  举报