iphone - how to check if the file is a directory , audio , video or image?

后端 未结 5 1290
长发绾君心
长发绾君心 2021-01-31 02:54

Following my program shows contents of Documents directory and is displayed in a tableView . But the Documents directory contains some directories , some audio , some video , an

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 03:45

    Just in case of image file type

    -(BOOL)isImageSource:(NSURL*)URL
    {
        CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)URL, NULL);
        NSString *UTI = (__bridge NSString*)CGImageSourceGetType(source);
        CFRelease(source);
    
        CFArrayRef mySourceTypes = CGImageSourceCopyTypeIdentifiers();
        NSArray *array = (__bridge NSArray*)mySourceTypes;
        CFRelease(mySourceTypes);
    
        return [array containsObject:UTI];
    }
    

提交回复
热议问题