zoukankan      html  css  js  c++  java
  • iphone 获取文件mimeType 方法

    - (NSString *)getMimeType:(NSString *)fileAbsolutePath error:(NSError *)error
    {
        NSString* fullPath = [fileAbsolutePath stringByExpandingTildeInPath];
        NSURL* fileUrl = [NSURL fileURLWithPath:fullPath]; 
        NSURLRequest* fileUrlRequest = [NSURLRequest requestWithURL: fileUrl];
        NSURLResponse* response = nil;
        [NSURLConnection sendSynchronousRequest:fileUrlRequest returningResponse:&response error:&error];
        return[response MIMEType];

    }

       // need MobileCoreServices.framework

       //#import <MobileCoreServices/MobileCoreServices.h>
       //#import <CoreFoundation/CoreFoundation.h>

       CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)@"xls", NULL);
       CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType);
       CFRelease(UTI);
      
       NSString *mimeType = [(NSString *)MIMEType autorelease];
       NSLog(mimeType); // output "application/vnd.ms-excel"

    //

  • 相关阅读:
    opencv-识别手写数字
    opencv-图像遍历
    533. Lonely Pixel II
    531. Lonely Pixel I
    495. Teemo Attacking
    370. Range Addition
    487. Max Consecutive Ones II
    485. Max Consecutive Ones
    414. Third Maximum Number
    90. Subsets II
  • 原文地址:https://www.cnblogs.com/likwo/p/1971147.html
Copyright © 2011-2022 走看看