mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-10 05:36:30 +08:00
Implemented MIMETypeForPathExtension for NSURL and NSString. refs #409
Refactored duplicated code for returning the MIME Type based on file path extension using Core Services UTI.
This commit is contained in:
@@ -18,6 +18,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#if TARGET_OS_MAC
|
||||
#import <CoreServices/CoreServices.h>
|
||||
#elif TARGET_OS_IPHONE
|
||||
#import <MobileCoreServices/UTType.h>
|
||||
#endif
|
||||
#import "NSString+RestKit.h"
|
||||
#import "../Network/RKClient.h"
|
||||
#import "RKFixCategoryBug.h"
|
||||
@@ -112,4 +117,19 @@ RK_FIX_CATEGORY_BUG(NSString_RestKit)
|
||||
return [self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
- (NSString *)MIMETypeForPathExtension {
|
||||
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[self pathExtension], NULL);
|
||||
if (uti != NULL) {
|
||||
CFStringRef mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
|
||||
CFRelease(uti);
|
||||
if (mime != NULL) {
|
||||
NSString *type = [NSString stringWithString:(NSString *)mime];
|
||||
CFRelease(mime);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user