一:MiMEType:一般可以再百度上搜索到相应文件的MiMEType,或是利用c语言的api去获取文件的MiMEType

//对该文件发送一个异步请求,拿到文件的MIMEType

- (void)MIMEType

{

//    NSString *file = @"file:///Users/文顶顶/Desktop/test.png";

[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"/Users/文顶顶/Desktop/test.png"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * __nullable response, NSData * __nullable data, NSError * __nullable connectionError) {

//       response.MIMEType

NSLog(@"%@",response.MIMEType);

}];

}

```

(2)通过UTTypeCopyPreferredTagWithClass方法

```objc

//注意:需要依赖于框架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);

}

```

二:多线程文件下载思路:将下载文件分成若干段,每段任务创建一条线程,多个任务并发执行下载文件的操作,不能利用输出流进行文件二进制数据data的拼接,否则会出现数据错乱。利用文件句柄,在代理方法中,接受到数据后,判断是哪条线程,再根据线程的不同,将文件句柄的位置偏移到seekoffset,偏移到相应线程的下载的地方

三:文件的压缩和解压缩

#import "ViewController.h"
#import "SSZipArchive.h" @interface ViewController () @end @implementation ViewController
-(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"
];
/*
第一个参数:压缩文件的存放位置
第二个参数:要压缩哪些文件(路径)
*/
//[SSZipArchive createZipFileAtPath:@"/Users/xiaomage/Desktop/Test.zip" withFilesAtPaths:arrayM];
[SSZipArchive createZipFileAtPath:@"/Users/xiaomage/Desktop/Test.zip" withFilesAtPaths:arrayM withPassword:@""];
} -(void)zip2
{
/*
第一个参数:压缩文件存放位置
第二个参数:要压缩的文件夹(目录)
*/
[SSZipArchive createZipFileAtPath:@"/Users/xiaomage/Desktop/demo.zip" withContentsOfDirectory:@"/Users/xiaomage/Desktop/demo"];
} -(void)unzip
{
/*
第一个参数:要解压的文件在哪里
第二个参数:文件应该解压到什么地方
*/
//[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, long entryNumber, long total) {
NSLog(@"%zd---%zd",entryNumber,total); } completionHandler:^(NSString *path, BOOL succeeded, NSError *error) { NSLog(@"%@",path);
}];
} @end

ios开发网络学习五:MiMEType ,多线程下载文件思路,文件的压缩和解压缩的更多相关文章

  1. ios开发网络学习五:输出流以及文件上传

    一:输出流 #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelega ...

  2. ios开发网络学习九:NSURLSessionDownloadTask实现大文件下载

    一:NSURLSessionDownloadTask:实现文件下载:无法监听进度 #import "ViewController.h" @interface ViewControl ...

  3. ios开发网络学习十一:NSURLSessionDataTask离线断点下载(断点续传)

    #import "ViewController.h" #define FileName @"121212.mp4" @interface ViewControl ...

  4. ios开发网络学习四:NSURLConnection大文件断点下载

    #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...

  5. ios开发网络学习AFN框架的使用一:get和post请求

    #import "ViewController.h" #import "AFNetworking.h" @interface ViewController () ...

  6. ios开发网络学习十二:NSURLSession实现文件上传

    #import "ViewController.h" // ----WebKitFormBoundaryvMI3CAV0sGUtL8tr #define Kboundary @&q ...

  7. ios开发runtime学习五:KVC以及KVO,利用runtime实现字典转模型

    一:KVC和KVO的学习 #import "StatusItem.h" /* 1:总结:KVC赋值:1:setValuesForKeysWithDictionary实现原理:遍历字 ...

  8. ios开发网络学习三:NSURLConnection小文件大文件下载

    一:小文件下载 #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDele ...

  9. ios开发网络学习:一:NSURLConnection发送GET,POST请求

    #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...

随机推荐

  1. LAMP+YII框架配置中遇到的问题

    以下列出了不同问题及答案: 1. 在yii框架中,改动数据库信息,主要有main.php和database.php两个文件. 2. 问题: watermark/2/text/aHR0cDovL2Jsb ...

  2. 6.Windows 二进制文件 (.exe)安装--终端安装

    转自:http://www.runoob.com/nodejs/nodejs-tutorial.html 32 位安装包下载地址 : http://nodejs.org/dist/v0.10.26/n ...

  3. affix附加导航插件

    <style> a:focus { outline: none; } .nav-pills { width: 150px; } .nav-pills.affix { top : 10px; ...

  4. 深入理解Linux启动过程

    深入理解Linux启动过程       本文详细分析了Linux桌面操作系统的启动过程,涉及到BIOS系统.LILO 和GRUB引导装载程序,以及bootsect.setup.vmlinux等映像文件 ...

  5. C# 异步延时执行

    https://blog.csdn.net/xiawu1990/article/details/78350253?utm_source=blogxgwz7 var t = Task.Run(async ...

  6. Android-ViewPager+Fragment数据更新问题

    由于FragmentPagerAdapter内部存在缓存.因此调用notifyDataSetChanged()并不可以去更新Fragment的内容. 參考:http://www.devba.com/i ...

  7. [Python] The get() method on Python dicts and its "default" arg

    # The get() method on dicts # and its "default" argument name_for_userid = { 382: "Al ...

  8. PHP盛宴——经常使用函数集锦

    近期写了蛮多PHP,也接触到挺多经常使用的函数,大多都记了笔记,发个博客出来.共同学习.事实上感觉学习一门语言,语法逻辑是软素养.而对语言的熟悉程度仅仅能随着使用时间的增长而慢慢增长,当对一门语言的函 ...

  9. bootstrap课程11 模态框如何使用

    bootstrap课程11 模态框如何使用 一.总结 一句话总结:多看手册咯. 1.模态框对应的英文单词是什么? modal,而不是madel 2.bootstrap中如何关闭某个效果? 比如要关掉m ...

  10. 微信支付v2开发(9) 标记客户投诉处理状态

    本文介绍微信支付中如何标记客户投诉的处理状态. 一.API Api 的 url 为: https://api.weixin.qq.com/payfeedback/update?access_token ...