mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-07 01:41:46 +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:
@@ -32,7 +32,6 @@
|
||||
#define RKLogComponent lcl_cRestKitCoreData
|
||||
|
||||
@interface RKManagedObjectSeeder (Private)
|
||||
- (NSString *)mimeTypeForExtension:(NSString *)extension;
|
||||
- (id)initWithObjectManager:(RKObjectManager*)manager;
|
||||
- (void)seedObjectsFromFileNames:(NSArray*)fileNames;
|
||||
@end
|
||||
@@ -122,7 +121,7 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
NSString* payload = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
|
||||
|
||||
if (payload) {
|
||||
NSString* MIMEType = [self mimeTypeForExtension:[fileName pathExtension]];
|
||||
NSString* MIMEType = [fileName MIMETypeForPathExtension];
|
||||
if (MIMEType == nil) {
|
||||
// Default the MIME type to the value of the Accept header if we couldn't detect it...
|
||||
MIMEType = _manager.acceptMIMEType;
|
||||
@@ -180,21 +179,4 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
- (NSString *)mimeTypeForExtension:(NSString *)extension {
|
||||
if (NULL != UTTypeCreatePreferredIdentifierForTag) {
|
||||
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)extension, 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