|
|
|
|
@ -16,17 +16,25 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
@implementation MIMETypeUtil
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedVideoMIMETypesToExtensionTypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"video/3gpp" : @"3gp",
|
|
|
|
|
@"video/3gpp2" : @"3g2",
|
|
|
|
|
@"video/mp4" : @"mp4",
|
|
|
|
|
@"video/quicktime" : @"mov",
|
|
|
|
|
@"video/x-m4v" : @"m4v"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedAudioMIMETypesToExtensionTypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"audio/aac" : @"m4a",
|
|
|
|
|
@"audio/x-m4p" : @"m4p",
|
|
|
|
|
@"audio/x-m4b" : @"m4b",
|
|
|
|
|
@ -46,10 +54,15 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
@"audio/3gpp2" : @"3g2",
|
|
|
|
|
@"audio/3gpp" : @"3gp"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedImageMIMETypesToExtensionTypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"image/jpeg" : @"jpeg",
|
|
|
|
|
@"image/pjpeg" : @"jpeg",
|
|
|
|
|
OWSMimeTypeImagePng : @"png",
|
|
|
|
|
@ -58,23 +71,38 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
@"image/bmp" : @"bmp",
|
|
|
|
|
@"image/x-windows-bmp" : @"bmp"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedAnimatedMIMETypesToExtensionTypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"image/gif" : @"gif",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedBinaryDataMIMETypesToExtensionTypes
|
|
|
|
|
{
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
OWSMimeTypeApplicationOctetStream : @"dat",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedVideoExtensionTypesToMIMETypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"3gp" : @"video/3gpp",
|
|
|
|
|
@"3gpp" : @"video/3gpp",
|
|
|
|
|
@"3gp2" : @"video/3gpp2",
|
|
|
|
|
@ -84,9 +112,15 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
@"mqv" : @"video/quicktime",
|
|
|
|
|
@"m4v" : @"video/x-m4v"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedAudioExtensionTypesToMIMETypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"3gp" : @"audio/3gpp",
|
|
|
|
|
@"3gpp" : @"@audio/3gpp",
|
|
|
|
|
@"3g2" : @"audio/3gpp2",
|
|
|
|
|
@ -107,10 +141,15 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
@"m4b" : @"audio/x-m4b",
|
|
|
|
|
@"m4p" : @"audio/x-m4p"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedImageExtensionTypesToMIMETypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"png" : OWSMimeTypeImagePng,
|
|
|
|
|
@"x-png" : OWSMimeTypeImagePng,
|
|
|
|
|
@"jfif" : @"image/jpeg",
|
|
|
|
|
@ -123,12 +162,19 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
@"tif" : @"image/tiff",
|
|
|
|
|
@"tiff" : @"image/tiff"
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSDictionary *)supportedAnimatedExtensionTypesToMIMETypes {
|
|
|
|
|
return @{
|
|
|
|
|
static NSDictionary *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = @{
|
|
|
|
|
@"gif" : @"image/gif",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (BOOL)isSupportedVideoMIMEType:(NSString *)contentType {
|
|
|
|
|
@ -328,22 +374,46 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
|
|
|
|
|
|
|
|
|
|
+ (NSSet<NSString *> *)supportedVideoUTITypes
|
|
|
|
|
{
|
|
|
|
|
return [self utiTypesForMIMETypes:[self supportedVideoMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
static NSSet<NSString *> *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = [self utiTypesForMIMETypes:[self supportedVideoMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSSet<NSString *> *)supportedAudioUTITypes
|
|
|
|
|
{
|
|
|
|
|
return [self utiTypesForMIMETypes:[self supportedAudioMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
static NSSet<NSString *> *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = [self utiTypesForMIMETypes:[self supportedAudioMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSSet<NSString *> *)supportedImageUTITypes
|
|
|
|
|
{
|
|
|
|
|
return [self utiTypesForMIMETypes:[self supportedImageMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
static NSSet<NSString *> *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = [self utiTypesForMIMETypes:[self supportedImageMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSSet<NSString *> *)supportedAnimatedImageUTITypes
|
|
|
|
|
{
|
|
|
|
|
return [self utiTypesForMIMETypes:[self supportedAnimatedMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
static NSSet<NSString *> *result = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
result = [self utiTypesForMIMETypes:[self supportedAnimatedMIMETypesToExtensionTypes].allKeys];
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|