A: MiMEType: Generally can be Baidu on the search for the corresponding file MiMEType, or use the C language API to get the file MiMEType
;
Send an asynchronous request to the file to get the file's MimeType
-(void) MIMEType
{
NSString *file = @ "file:///Users/top/desktop/test.png";
[Nsurlconnection sendasynchronousrequest:[nsurlrequest requestwithurl:[nsurl fileurlwithpath:@/users/text Top/desktop /test.png "] Queue:[nsoperationqueue Mainqueue] completionhandler:^ (nsurlresponse * __nullable response, NSData * __) Nullable data, Nserror * __nullable connectionerror) {
Response. MIMEType
NSLog (@ "%@", response. MIMEType);
}];
}
```
(2) through the Uttypecopypreferredtagwithclass method
"' OBJC
Note: You need to rely on frame mobilecoreservices
-(NSString *) Mimetypeforfileatpath: (NSString *) path
{
if (![ [[Nsfilemanager alloc] init] Fileexistsatpath:path]) {
return nil;
}
Cfstringref UTI = Uttypecreatepreferredidentifierfortag (Kuttagclassfilenameextension, (__bridge CFStringRef) [path Pathextension], NULL);
Cfstringref MIMEType = Uttypecopypreferredtagwithclass (UTI, Kuttagclassmimetype);
Cfrelease (UTI);
if (! MIMEType) {
return @ "Application/octet-stream";
}
Return (__bridge NSString *) (MIMEType);
}
```
Two: Multi-threaded file download idea: The download file into a number of paragraphs, each task creates a thread, multiple tasks concurrently perform the operation of downloading files, the output stream can not be used for file binary data splicing, otherwise there will be data confusion. Using the file handle, in the proxy method, after receiving the data, determine which thread, and then depending on the thread, the location of the file handle is offset to seekoffset, offset to the corresponding thread of the download place
Three: File compression and decompression
#import "ViewController.h"#import "SSZipArchive.h"@interfaceViewcontroller ()@end@implementationViewcontroller-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{[self unzip];}-(void) zip{Nsarray*arraym = @[ @"/users/xiaomage/desktop/snip20160226_2.png", @"/users/xiaomage/desktop/snip20160226_6.png" ]; /*first parameter: The location of the compressed file The second parameter: which files to compress (path)*/ //[ssziparchive createzipfileatpath:@ "/users/xiaomage/desktop/test.zip" Withfilesatpaths:arraym];[Ssziparchive Createzipfileatpath:@"/users/xiaomage/desktop/test.zip"Withfilesatpaths:arraym Withpassword:@"123456"];}-(void) zip2{/*first parameter: Compressed file storage location The second parameter: folder to compress (directory)*/[ssziparchive Createzipfileatpath:@"/users/xiaomage/desktop/demo.zip"Withcontentsofdirectory:@"/users/xiaomage/desktop/demo"];}-(void) unzip{/*first parameter: Where to unzip the file the second parameter: where should the file be extracted?*/ //[ssziparchive unzipfileatpath:@ "/users/xiaomage/desktop/demo.zip" todestination:@ "/Users/xiaomage/Desktop/xx "];[ssziparchive Unzipfileatpath:@"/users/xiaomage/desktop/demo.zip"Todestination:@"/users/xiaomage/desktop/xx"progresshandler:^ (NSString *entry, Unz_file_info Zipinfo,LongEntrynumber,LongTotal ) {NSLog (@"%ZD---%zd", Entrynumber,total); } Completionhandler:^ (NSString *path, BOOL succeeded, Nserror *error) {NSLog (@"%@", path); }];}@end
iOS Development Network Learning Five: MiMEType, multi-threaded download file ideas, file compression and decompression