|
3 | 3 |
|
4 | 4 | @implementation MIMETypeUtil |
5 | 5 |
|
6 | | -static NSDictionary *supportedVideoMIMETypesToExtensionTypes; |
7 | | -static NSDictionary *supportedAudioMIMETypesToExtensionTypes; |
8 | | -static NSDictionary *supportedImageMIMETypesToExtensionTypes; |
9 | | -static NSDictionary *supportedVideoExtensionTypesToMIMETypes; |
10 | | -static NSDictionary *supportedAudioExtensionTypesToMIMETypes; |
11 | | -static NSDictionary *supportedImageExtensionTypesToMIMETypes; |
12 | | - |
13 | | -#pragma mark uses file extensions or MIME types only |
14 | | -+(void) initialize { |
15 | | - // Initialize must be called before this class is used. Could later be in e.g. a .plist |
16 | | - supportedVideoMIMETypesToExtensionTypes =@{@"video/3gpp":@"3gp", |
17 | | - @"video/3gpp2":@"3g2", |
18 | | - @"video/mp4":@"mp4", |
19 | | - @"video/quicktime":@"mov", |
20 | | - @"video/x-m4v":@"m4v" |
21 | | - }; |
22 | | - |
23 | | - supportedAudioMIMETypesToExtensionTypes = @{@"audio/x-m4p":@"m4p", |
24 | | - @"audio/x-m4b":@"m4b", |
25 | | - @"audio/x-m4a":@"m4a", |
26 | | - @"audio/wav":@"wav", |
27 | | - @"audio/x-wav":@"wav", |
28 | | - @"audio/x-mpeg":@"mp3", |
29 | | - @"audio/mpeg":@"mp3", |
30 | | - @"audio/mp4":@"mp4", |
31 | | - @"audio/mp3":@"mp3", |
32 | | - @"audio/mpeg3":@"mp3", |
33 | | - @"audio/x-mp3":@"mp3", |
34 | | - @"audio/x-mpeg3":@"mp3", |
35 | | - @"audio/amr":@"amr", |
36 | | - @"audio/aiff":@"aiff", |
37 | | - @"audio/x-aiff":@"aiff", |
38 | | - @"audio/3gpp2":@"3g2", |
39 | | - @"audio/3gpp":@"3gp" |
40 | | - }; |
41 | | - |
42 | | - |
43 | | - supportedImageMIMETypesToExtensionTypes = @{@"image/jpeg":@"jpeg", |
44 | | - @"image/pjpeg":@"jpeg", |
45 | | - @"image/png":@"png", |
46 | | - @"image/gif":@"gif", |
47 | | - @"image/tiff":@"tif", |
48 | | - @"image/x-tiff":@"tif", |
49 | | - @"image/bmp":@"bmp", |
50 | | - @"image/x-windows-bmp":@"bmp" |
51 | | - }; |
52 | | - |
53 | | - |
54 | | - supportedVideoExtensionTypesToMIMETypes = @{@"3gp":@"video/3gpp", |
55 | | - @"3gpp":@"video/3gpp", |
56 | | - @"3gp2":@"video/3gpp2", |
57 | | - @"3gpp2":@"video/3gpp2", |
58 | | - @"mp4":@"video/mp4", |
59 | | - @"mov":@"video/quicktime", |
60 | | - @"mqv":@"video/quicktime", |
61 | | - @"m4v":@"video/x-m4v" |
62 | | - }; |
63 | | - |
64 | | - supportedAudioExtensionTypesToMIMETypes = @{@"3gp":@"audio/3gpp", |
65 | | - @"3gpp":@"@audio/3gpp", |
66 | | - @"3g2":@"audio/3gpp2", |
67 | | - @"3gp2":@"audio/3gpp2", |
68 | | - @"aiff":@"audio/aiff", |
69 | | - @"aif":@"audio/aiff", |
70 | | - @"aifc":@"audio/aiff", |
71 | | - @"cdda":@"audio/aiff", |
72 | | - @"amr":@"audio/amr", |
73 | | - @"mp3":@"audio/mp3", |
74 | | - @"swa":@"audio/mp3", |
75 | | - @"mp4":@"audio/mp4", |
76 | | - @"mpeg":@"audio/mpeg", |
77 | | - @"mpg":@"audio/mpeg", |
78 | | - @"wav":@"audio/wav", |
79 | | - @"bwf":@"audio/wav", |
80 | | - @"m4a":@"audio/x-m4a", |
81 | | - @"m4b":@"audio/x-m4b", |
82 | | - @"m4p":@"audio/x-m4p" |
83 | | - }; |
84 | | - |
85 | | - supportedImageExtensionTypesToMIMETypes = @{@"png":@"image/png", |
86 | | - @"x-png":@"image/png", |
87 | | - @"jfif":@"image/jpeg", |
88 | | - @"jfif":@"image/pjpeg", |
89 | | - @"jfif-tbnl":@"image/jpeg", |
90 | | - @"jpe":@"image/jpeg", |
91 | | - @"jpe":@"image/pjpeg", |
92 | | - @"jpeg":@"image/jpeg", |
93 | | - @"jpg":@"image/jpeg", |
94 | | - @"gif":@"image/gif", |
95 | | - @"tif":@"image/tiff", |
96 | | - @"tiff":@"image/tiff" |
97 | | - }; |
| 6 | ++ (NSDictionary*)supportedVideoMIMETypesToExtensionTypes{ |
| 7 | + return @{@"video/3gpp":@"3gp", |
| 8 | + @"video/3gpp2":@"3g2", |
| 9 | + @"video/mp4":@"mp4", |
| 10 | + @"video/quicktime":@"mov", |
| 11 | + @"video/x-m4v":@"m4v" |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | ++ (NSDictionary*)supportedAudioMIMETypesToExtensionTypes{ |
| 16 | + return @{@"audio/x-m4p":@"m4p", |
| 17 | + @"audio/x-m4b":@"m4b", |
| 18 | + @"audio/x-m4a":@"m4a", |
| 19 | + @"audio/wav":@"wav", |
| 20 | + @"audio/x-wav":@"wav", |
| 21 | + @"audio/x-mpeg":@"mp3", |
| 22 | + @"audio/mpeg":@"mp3", |
| 23 | + @"audio/mp4":@"mp4", |
| 24 | + @"audio/mp3":@"mp3", |
| 25 | + @"audio/mpeg3":@"mp3", |
| 26 | + @"audio/x-mp3":@"mp3", |
| 27 | + @"audio/x-mpeg3":@"mp3", |
| 28 | + @"audio/amr":@"amr", |
| 29 | + @"audio/aiff":@"aiff", |
| 30 | + @"audio/x-aiff":@"aiff", |
| 31 | + @"audio/3gpp2":@"3g2", |
| 32 | + @"audio/3gpp":@"3gp" |
| 33 | + }; |
| 34 | +} |
| 35 | + |
| 36 | ++ (NSDictionary*)supportedImageMIMETypesToExtensionTypes{ |
| 37 | + return @{@"image/jpeg":@"jpeg", |
| 38 | + @"image/pjpeg":@"jpeg", |
| 39 | + @"image/png":@"png", |
| 40 | + @"image/gif":@"gif", |
| 41 | + @"image/tiff":@"tif", |
| 42 | + @"image/x-tiff":@"tif", |
| 43 | + @"image/bmp":@"bmp", |
| 44 | + @"image/x-windows-bmp":@"bmp" |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | ++ (NSDictionary*)supportedVideoExtensionTypesToMIMETypes{ |
| 49 | + return @{@"3gp":@"video/3gpp", |
| 50 | + @"3gpp":@"video/3gpp", |
| 51 | + @"3gp2":@"video/3gpp2", |
| 52 | + @"3gpp2":@"video/3gpp2", |
| 53 | + @"mp4":@"video/mp4", |
| 54 | + @"mov":@"video/quicktime", |
| 55 | + @"mqv":@"video/quicktime", |
| 56 | + @"m4v":@"video/x-m4v" |
| 57 | + }; |
| 58 | +} |
| 59 | ++ (NSDictionary*)supportedAudioExtensionTypesToMIMETypes{ |
| 60 | + return @{@"3gp":@"audio/3gpp", |
| 61 | + @"3gpp":@"@audio/3gpp", |
| 62 | + @"3g2":@"audio/3gpp2", |
| 63 | + @"3gp2":@"audio/3gpp2", |
| 64 | + @"aiff":@"audio/aiff", |
| 65 | + @"aif":@"audio/aiff", |
| 66 | + @"aifc":@"audio/aiff", |
| 67 | + @"cdda":@"audio/aiff", |
| 68 | + @"amr":@"audio/amr", |
| 69 | + @"mp3":@"audio/mp3", |
| 70 | + @"swa":@"audio/mp3", |
| 71 | + @"mp4":@"audio/mp4", |
| 72 | + @"mpeg":@"audio/mpeg", |
| 73 | + @"mpg":@"audio/mpeg", |
| 74 | + @"wav":@"audio/wav", |
| 75 | + @"bwf":@"audio/wav", |
| 76 | + @"m4a":@"audio/x-m4a", |
| 77 | + @"m4b":@"audio/x-m4b", |
| 78 | + @"m4p":@"audio/x-m4p" |
| 79 | + }; |
| 80 | +} |
| 81 | + |
| 82 | ++ (NSDictionary*)supportedImageExtensionTypesToMIMETypes{ |
| 83 | + return @{@"png":@"image/png", |
| 84 | + @"x-png":@"image/png", |
| 85 | + @"jfif":@"image/jpeg", |
| 86 | + @"jfif":@"image/pjpeg", |
| 87 | + @"jfif-tbnl":@"image/jpeg", |
| 88 | + @"jpe":@"image/jpeg", |
| 89 | + @"jpe":@"image/pjpeg", |
| 90 | + @"jpeg":@"image/jpeg", |
| 91 | + @"jpg":@"image/jpeg", |
| 92 | + @"gif":@"image/gif", |
| 93 | + @"tif":@"image/tiff", |
| 94 | + @"tiff":@"image/tiff" |
| 95 | + }; |
98 | 96 | } |
99 | 97 |
|
100 | 98 | +(BOOL) isSupportedVideoMIMEType:(NSString*)contentType { |
101 | | - return [supportedVideoMIMETypesToExtensionTypes objectForKey:contentType]!=nil; |
| 99 | + return [[self supportedVideoMIMETypesToExtensionTypes] objectForKey:contentType]!=nil; |
102 | 100 | } |
103 | 101 |
|
104 | 102 | +(BOOL) isSupportedAudioMIMEType:(NSString*)contentType { |
105 | | - return [supportedAudioMIMETypesToExtensionTypes objectForKey:contentType]!=nil; |
| 103 | + return [[self supportedAudioMIMETypesToExtensionTypes] objectForKey:contentType]!=nil; |
106 | 104 | } |
107 | 105 |
|
108 | 106 | +(BOOL) isSupportedImageMIMEType:(NSString*)contentType { |
109 | | - return [supportedImageMIMETypesToExtensionTypes objectForKey:contentType]!=nil; |
| 107 | + return [[self supportedImageMIMETypesToExtensionTypes] objectForKey:contentType]!=nil; |
110 | 108 | } |
111 | 109 |
|
112 | 110 | +(BOOL) isSupportedMIMEType:(NSString*)contentType { |
113 | 111 | return [self isSupportedImageMIMEType:contentType] || [self isSupportedAudioMIMEType:contentType] || [self isSupportedVideoMIMEType:contentType]; |
114 | 112 | } |
115 | 113 |
|
116 | 114 | +(BOOL) isSupportedVideoFile:(NSString*) filePath { |
117 | | - return [supportedVideoExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil; |
| 115 | + return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil; |
118 | 116 | } |
119 | 117 |
|
120 | 118 | +(BOOL) isSupportedAudioFile:(NSString*) filePath { |
121 | | - return [supportedAudioExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil; |
| 119 | + return [[self supportedAudioExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil; |
122 | 120 | } |
123 | 121 |
|
124 | 122 | +(BOOL) isSupportedImageFile:(NSString*) filePath { |
125 | | - return [supportedImageExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil; |
| 123 | + return [[self supportedImageExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil; |
126 | 124 | } |
127 | 125 |
|
128 | 126 | +(NSString*) getSupportedExtensionFromVideoMIMEType:(NSString*)supportedMIMEType { |
129 | | - return [supportedVideoMIMETypesToExtensionTypes objectForKey:supportedMIMEType]; |
| 127 | + return [[self supportedVideoMIMETypesToExtensionTypes] objectForKey:supportedMIMEType]; |
130 | 128 | } |
131 | 129 |
|
132 | 130 | +(NSString*) getSupportedExtensionFromAudioMIMEType:(NSString*)supportedMIMEType { |
133 | | - return [supportedAudioMIMETypesToExtensionTypes objectForKey:supportedMIMEType]; |
| 131 | + return [[self supportedAudioMIMETypesToExtensionTypes] objectForKey:supportedMIMEType]; |
134 | 132 | } |
135 | 133 |
|
136 | 134 | +(NSString*) getSupportedExtensionFromImageMIMEType:(NSString*)supportedMIMEType { |
137 | | - return [supportedImageMIMETypesToExtensionTypes objectForKey:supportedMIMEType]; |
| 135 | + return [[self supportedImageMIMETypesToExtensionTypes] objectForKey:supportedMIMEType]; |
138 | 136 | } |
139 | 137 |
|
140 | 138 | +(NSString*) getSupportedMIMETypeFromVideoFile:(NSString*)supportedVideoFile { |
141 | | - return [supportedVideoExtensionTypesToMIMETypes objectForKey:[supportedVideoFile pathExtension]]; |
142 | | -} |
| 139 | + return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[supportedVideoFile pathExtension]]; |
| 140 | +} |
143 | 141 |
|
144 | 142 | +(NSString*) getSupportedMIMETypeFromAudioFile:(NSString*)supportedAudioFile { |
145 | | - return [supportedAudioExtensionTypesToMIMETypes objectForKey:[supportedAudioFile pathExtension]]; |
| 143 | + return [[self supportedAudioExtensionTypesToMIMETypes] objectForKey:[supportedAudioFile pathExtension]]; |
146 | 144 | } |
147 | 145 |
|
148 | 146 | +(NSString*) getSupportedMIMETypeFromImageFile:(NSString*)supportedImageFile { |
149 | | - return [supportedImageExtensionTypesToMIMETypes objectForKey:[supportedImageFile pathExtension]]; |
| 147 | + return [[self supportedImageExtensionTypesToMIMETypes] objectForKey:[supportedImageFile pathExtension]]; |
150 | 148 | } |
151 | 149 |
|
152 | 150 | #pragma mark uses bytes |
153 | 151 | +(NSString*) getSupportedImageMIMETypeFromImage:(UIImage*)image { |
154 | | - return [image contentType]; |
| 152 | + return [image contentType]; |
155 | 153 | } |
156 | 154 |
|
157 | 155 | +(BOOL) getIsSupportedTypeFromImage:(UIImage*)image { |
158 | | - return [image isSupportedImageType]; |
| 156 | + return [image isSupportedImageType]; |
159 | 157 | } |
160 | 158 |
|
161 | 159 | #pragma mark full attachment utilities |
@@ -189,7 +187,7 @@ + (NSString*)filePathForAttachment:(NSString*)uniqueId ofMIMEType:(NSString*)con |
189 | 187 | +(NSURL*) simLinkCorrectExtensionOfFile:(NSURL*)mediaURL ofMIMEType:(NSString*)contentType { |
190 | 188 | if([self isAudio:contentType]) { |
191 | 189 | // Audio files in current framework require changing to have extension for player |
192 | | - return [self changeFile:mediaURL toHaveExtension:[supportedAudioMIMETypesToExtensionTypes objectForKey:contentType]]; |
| 190 | + return [self changeFile:mediaURL toHaveExtension:[[self supportedAudioMIMETypesToExtensionTypes] objectForKey:contentType]]; |
193 | 191 | } |
194 | 192 | return mediaURL; |
195 | 193 | } |
|
0 commit comments