获得文件的MIMEType

NSURL *url = [NSURL fileURLWithPath:@"/Users/xiaomage/Desktop/test.png"];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

// 第一种

 [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

    NSLog(@"%@", response.MIMEType);

}];

// 第二种

NSURLResponse *response = nil;

[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];

NSLog(@"%@", response.MIMEType);

你可能感兴趣的:(获得文件的MIMEType)