In my current application I am downloading few files from server, and storing them locally.
Based on extension of file I am loading the file in appropriate view. Example: 1. file extensions: mov, 3gp, m4a, etc., => display in media player. 2. file extensions: rtf, pptx, numbers, etc., =>display in UIWebView. 3. file extensions: gif, png, xbm, etc., =>display in UIImageView. Problem is: some of the downloaded files may not have any extension. One approach which I found is- in connectionDidFinishLoading obtain MIMEType from response and from that obtain file extension. I used below code, for the same: - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ CFStringRef mimeType = (__bridge CFStringRef)[_respo MIMEType]; CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType, NULL); CFStringRef extension = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension); NSString *fileName = [NSString stringWithFormat:@"%@.%@", [[_respo suggestedFilename] stringByDeletingPathExtension], (__bridge NSString *)extension]; [[NSFileManager defaultManager] createFileAtPath:[[self docsDir] stringByAppendingPathComponent:[NSString stringWithFormat:@"Downloads/%@", fileName]] contents:_downloadedData attributes:nil]; } Now my questions are: 1. Is there any other way to identify file extension for the files without extensions, say from NSData object? 2. In place of checking file extension, is there any other way to show the file in appropriate view? Please suggest. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com