iOS_NSURLSessionDownloadTask_显示加载进度_断点续传(网络中断情况).

iOS小技能: HTTPS问题分析汇总:1、NSURLSessionTask finished with error - code: -1005(请求超时)2、Error Code=-999 - request.timeoutInterval = 5.0; + request.timeoutInterval = 30.0; 阅读详情
  • 说明:

    • 本文将介绍使用NSURLSessionDownloadDelegate的代理方法实现显示加载进度和断点续传(网络中断情况, 不是退出程序情况. 只要不是退出程序的情况下, 下载失败都可以用本文的方法实现断点续传).
    • 实现功能的方法并不唯一, 大家要灵活使用.

    • session 类型 : default session.

    • session的创建方法: + sessionWithConfiguration:delegate:delegateQueue:

    • task 类型: download task.

    • 代码中所使用到的接口(例: http://2b2726fb22467.cdn.sohucs.com/55fbb97f13aa9.mp4) 都具有时效性, 建议测试时使用一个可以提供数据的新接口.

  • 请确保Xcode版本在6.4以上.

  • 文章中尽量不使用或少使用封装, 目的是让大家清楚为了实现功能所需要的官方核心API是哪些(如果使用封装, 会在封装外面加以注释)

  • 此文章由 @春雨 编写. 经 @Scott,@黑子 审核. 若转载此文章,请注明出处和作者

iOS_断点续传

核心API

Class :

  • NSURLSession
  • NSURLSessionConfiguration
  • NSURLSessionTask
    • NSURLSessionDownload

Delegate :

  • NSURLSessionDelegate
  • NSURLSessionTaskDelegate
  • NSURLSessionDownloadDelegate

涉及的API :

  • NSURLSession
/** 创建NSURLSession对象的类方法. */
+ (NSURLSession *)sessionWithConfiguration:(NSURLSessionConfiguration *)configuration delegate:(id<NSURLSessionDelegate>)delegate delegateQueue:(NSOperationQueue *)queue
/** 创建一个download任务, 用于恢复之前取消或者失败的download任务. */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData

/** 创建一个download任务, 用于恢复之前取消或者失败的download任务. 并回调Block块. */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler
/** 创建一个download任务, 用于恢复之前取消或者失败的download任务. 并带有一个处理任务完成的block块. */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler
  • NSURLSessionDownloadTask
/** 取消download任务, 并回调一个带续传数据的Block块. */
- (void)cancelByProducingResumeData:(void (^)(NSData *resumeData))completionHandler
  • NSURLSessionTask
/** 取消任务. */
- (void)cancel
  • NSURLSessionDownloadDelegate
/** 告诉delegate, download task已经完成. */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
/** 定期通知代理人下载进度. */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
/** 告诉代理人下载任务已经恢复. */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes
  • NSURLSessionTaskDelegate
/** 告诉delegate, task已经完成. */
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
  • NSURLSessionDownloadTask
 /** 取消下载并调用回调与恢复数据供以后使用. */
- (void)cancelByProducingResumeData:(void (^)(NSData *resumeData))completionHandler

功能实现

思路 :
  • 1 . 下载过程中显示加载进度.
  • 2 . 断点续传(网络中断)
    注: 判断网络状态.(用于测试)
  • 4 . 取消下载.
  • 5 . 其他方法.
Code :
1. 加载进度 和 2. 断点续传(网络中断)

注: 网络判断部分请查看iOS_AFNetworking_AFNetworkReachabilityManager(检测网络可达性)


#import "ViewController.h"
#import "AFNetworkReachabilityManager.h"

@interface ViewController ()<NSURLSessionDelegate, NSURLSessionDownloadDelegate, NSURLSessionTaskDelegate>

@property (nonatomic, strong) NSURLSessionDownloadTask *downloadTask; // 下载任务
@property (nonatomic, strong) NSURLSession *session; // 会话
@property (nonatomic, strong) NSData *resumData; // 续传数据
@property (nonatomic, strong) NSDate *lastDate; // 上次获取到数据的时间.

/** 两个label都是用Storybord创建的. */
@property (weak, nonatomic) IBOutlet UILabel *progressLabel;
@property (weak, nonatomic) IBOutlet UILabel *speedLabel;


@end


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self networkState];
    [self handleData];
}


- (void)handleData
{
    /** 创建默认配置的会话. */
    self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];/**< 注意: 我们设置了主线程. */



    /** 创建下载任务. */
    self.downloadTask = [_session downloadTaskWithURL:[NSURL URLWithString:@"http://2b2726fb22467.cdn.sohucs.com/55fbb97f13aa9.mp4"]];


    /** 开启下载任务. */
    [_downloadTask resume];

    /** 记载开始下载的时间. */
    self.lastDate = [NSDate date];
}

/** NSURLSessionDownloadDeleget 方法. 
 * bytesWritten 参数: 自上次调用该委托方法之后,传输的字节数。
 * totalBytesWritten 参数: 已经传输的总字节数.
 * totalBytesExpectedToWrite 参数: 应该传输的字节数(相当于下载数据的总字节数).
 */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
{

    /** 这次获取字节数的时间. */
    NSDate *currentDate = [NSDate date];
    /** 两次获取字节数的时间间隔. */
    NSTimeInterval time =[currentDate timeIntervalSinceDate:_lastDate];

    /** 时间间隔大于1秒, 再更新UI. */
    if (time >= 1) {
        /** 算出下载速度. */
        NSString *speedString = [NSString stringWithFormat:@"%.2lfKB", bytesWritten / time / 1024];
        /** 更新UI.(注意的部分请看 progressLabel.text的注.) */
        _speedLabel.text = speedString;

        /** 将这次的时间赋值给lastData属性. */
        _lastDate = currentDate;
    }



    /** 求当前的加载进度. */
    float progress = (float)totalBytesWritten / totalBytesExpectedToWrite;
    NSString *str = [NSString stringWithFormat:@"%.2f%%", progress * 100];

    /** 注: 
     * 在创建session时, 我们给delegateQueue设置的是主线程, 所以我们可以直接给progressLabeL的text赋值.
     * 但是, 如果设置的不是主线程或者是使用completionHandler块下载数据, 那么我们应该回到主线程更新UI.
     * 原因: delegateQueue参数的作用是给代理方法提供一个执行的队列, 这个队列跟下载数据没有关系, 只是说代理方法应该在这个队列执行. 如果delegateQueue是nil或者没有delegateQueue, 那么系统会自动创建一系列的队列, 让代理方法或者completionHandler块, 在这些队列里执行.
     */
    _progressLabel.text = str;
}

/** NSURLSessionDownloadDeleget 方法.
 * location 参数: 下载完成的数据存储的位置.
 */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{
    /** 取出Library文件的路径. */
    NSString *saveString = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject;

    /** 取出"55fbb97f13aa9.mp4" 字符串. */
    NSString *fileName = [NSURL URLWithString:@"http://2b2726fb22467.cdn.sohucs.com/55fbb97f13aa9.mp4"].lastPathComponent;
    /** 拼接成保存路径. */
    NSString *saveURL = [NSString stringWithFormat:@"%@/%@", saveString, fileName];

    /** 将下载好的数据复制到波哦村路径, 避免丢失. */
    NSError *error = nil;
    [[NSFileManager defaultManager] copyItemAtURL:location toURL:[NSURL fileURLWithPath:saveURL] error:&error];

}

/** NSURLSessionTaskDelegate 方法
 * 任务完成调用.(无论何种任务完成, 都会调用这个方法.)
 */
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{
    if (error) {
        /** 如果发生错误, 我们可以从error中获取到续传数据. */
        self.resumData =  [error.userInfo objectForKey:NSURLSessionDownloadTaskResumeData];

        NSLog(@"download error: %@", error);
    } else {
        NSLog(@"下载成功!");
    }
}

/** 对网络的判断. */ 
- (void)networkState
{
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"无网!");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
                if (_resumData) {

                    /** 如果resumData属性有值, 就重新创建一个download任务. */
                ��A   NSURLSessionDownloadTask *resumeDownloadTask = [_session downloadTaskWithResumeData:_resumData];
                    /** 也可以使用 downloadTaskWithResumeData:completionHandler: 方法创建. */
                    [resumeDownloadTask resume];
                }
                break;

            default:
                break;
        }
    }];

    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
}


/** NSURLSessionDownloadDeleget 方法.
 * 当使用 downloadTaskWithResumeData: 或者 downloadTaskWithResumeData:completionHandler: 方法创建download类型的任务时, 就会调用这个代理方法.
 * 之后跟正常的download任务都一样.
 */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes
{
    /** 目前笔者还不知道在这个方法内需要执行哪些操作, 所以只是先输出一下. */
    NSLog(@"download继续加载!");
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

注:
可以将 ��A 替换成以下代码, 在completionHandler的block块中处理接收到的数据.

 NSURLSessionDownloadTask *secondTask = [_session downloadTaskWithResumeData:self.resumData completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {

     // 当secondTask 完成时, 为了下载的文件不丢失, 需要将文件复制到另外的路径.

    NSString *fileName = [NSURL URLWithString:VIDEOURL].lastPathComponent;
    NSString *tempPath = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(), fileName];

    NSError *fileError = nil;
    [[NSFileManager defaultManager] copyItemAtURL:location toURL:[NSURL fileURLWithPath:tempPath] error:&fileError];                     

 }];
4 . 取消任务.

当执行下列代码时, 就可以取消任务, 并且可以获取到已经接收到的数据, 用于以后恢复下载.

[self.downloadTast cancelByProducingResumeData:^(NSData *resumeData) {

        _resumData = resumeData;
    }];

恢复下载任务的步骤和上面的方法相同.

如果以后不用恢复下载, 可以直接取消

[self.downloadTast cancel];
5 . 其他方法.

可以使用NSURLSessionTask的countOfBytesReceived 和 countOfBytesExpectedToReceive 属性计算加载进度. 还有可以用 countOfBytesSent 和 countOfBytesExpectedToSend 属性计算upload 任务.

(Demo的下载链接)[]

API 官方注释

  • NSURLSession
/** 
 * @brief  Creates a download task to resume a previously canceled or failed download.
 *
 * @param  <resumeData>  A data object that provides the data necessary to resume a download.
 * 
 * @return   The new session download task.
 */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData
/** 
 * @brief  Creates a download task to resume a previously canceled or failed download and calls a handler upon completion.
 *
 * @param  <resumeData> A data object that provides the data necessary to resume the download.
 * 
 * @param  <completionHandler>  The completion handler to call when the load request is complete. This handler is executed on the delegate queue.

Unless you have provided a custom delegate, this parameter must not be nil, because there is no other way to retrieve the response data.
 * 
 * @return   The new session download task.
 */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler
/** 
 * @brief  Tells the delegate that the download task has resumed downloading.
 *
 * @param  <session>    The session containing the download task that finished.
 * 
 * @param  <downloadTask>   The download task that resumed. See explanation in the discussion.
 * 
 * @param  <fileOffset> If the file's cache policy or last modified date prevents reuse of the existing content, then this value is zero. Otherwise, this value is an integer representing the number of bytes on disk that do not need to be retrieved again.

 * @param  <expectedTotalBytes> The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is NSURLSessionTransferSizeUnknown.
 */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler
  • NSURLSessionDownloadTask
/** 
 * @brief  Creates a download task to resume a previously canceled or failed download.
 *
 * @param  <completionHandler>  A completion handler that is called when the download has been successfully canceled.

If the download is resumable, the completion handler is provided with a resumeData object. Your app can later pass this object to a session’s downloadTaskWithResumeData: or downloadTaskWithResumeData:completionHandler: method to create a new task that resumes the download where it left off.
 * 
 */
- (void)cancelByProducingResumeData:(void (^)(NSData *resumeData))completionHandler
  • NSURLSessionTask
/** 
 * @brief  Cancels the task.
 */
- (void)cancel
  • NSURLSessionDownloadDelegate
/** 
 * @brief  Tells the delegate that a download task has finished downloading.
 *
 * @param  <session>    The session containing the download task that finished.
 * 
 * @param  <downloadTask>   The download task that finished.
 * 
 * @param  <location>   A file URL for the temporary file. Because the file is temporary, you must either open the file for reading or move it to a permanent location in your app’s sandbox container directory before returning from this delegate method.

If you choose to open the file for reading, you should do the actual reading in another thread to avoid blocking the delegate queue.

 */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
/** 
 * @brief  Periodically informs the delegate about the download’s progress.
 *
 * @param  <session>    The session containing the download task.
 * 
 * @param  <downloadTask>   The download task.
 * 
 * @param  <bytesWritten>   The number of bytes transferred since the last time this delegate method was called.
 * 
 * @param  <totalBytesWritten>  The total number of bytes transferred so far.
 *
 * @param  <totalBytesExpectedToWriteD> The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is NSURLSessionTransferSizeUnknown.
 */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
/** 
 * @brief  Tells the delegate that the download task has resumed downloading.
 *
 * @param  <session>    The download task that resumed. See explanation in the discussion.
 * 
 * @param  <downloadTask>   The download task that finished.
 * 
 * @param  <fileOffset> If the file's cache policy or last modified date prevents reuse of the existing content, then this value is zero. Otherwise, this value is an integer representing the number of bytes on disk that do not need to be retrieved again.
 * 
 * @param  <expectedTotalBytes> The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is NSURLSessionTransferSizeUnknown.
 *
 */
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes
  • NSURLSessionTaskDelegate
/** 
 * @brief  Tells the delegate that the task finished transferring data.
 *
 * @param  <session>    The session containing the task whose request finished transferring data.
 * 
 * @param  <task>   The task whose request finished transferring data.
 * 
 * @param  <error>  If an error occurred, an error object indicating how the transfer failed, otherwise NULL.
 * 
 */
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
  • NSURLSessionDownloadTask
 /** 
 * @brief  Cancels a download and calls a callback with resume data for later use.
 *
 * @param  <completionHandler>   A completion handler that is called when the download has been successfully canceled.

If the download is resumable, the completion handler is provided with a resumeData object. Your app can later pass this object to a session’s downloadTaskWithResumeData: or downloadTaskWithResumeData:completionHandler: method to create a new task that resumes the download where it left off.
 * 
 */

- (void)cancelByProducingResumeData:(void (^)(NSData *resumeData))completionHandler
POVME3口袋体积计算:从.ini配置到实战解析 本文详细解析了POVME3口袋体积计算工具,从核心原理、环境准备到实战应用。重点剖析了控制计算行为的.ini配置文件,包括如何定义口袋区域、精修范围及锁定目标,并提供了固定坐标与配体引导两种实战策略,帮助研究人员从分子动力学轨迹中量化分析蛋白质结合口袋的动态变化。 阅读详情

相关推荐

【HAL库-STM】智能温控按键小风扇【胎教级教学】

硬件设备:DHT11,0.96寸oled屏,二/三/四线风扇(不挑),面包板 、f10的精英板等等。当人在的风扇面前时可以自行控制风扇,不在面前时又想开风扇就让他温控自行开启,(在这里有一个想法就是加上蓝牙和wifi控制的功能能够远程遥控,这个如果做的再全一点就要自主研发是一个多功能app,这里没有做。针对这个dht11,我一开始是卡在了这个check函数里面,一直是我给完dht11低电平和高电平后,dht11不回复我低电平和高电平,这个不是我的问题,当时代码是没毛病的,这个点一直卡着我。吐血五天实现小成品

weixin_52451652的博客 1738

IOS开发:记录处理 Error Domain=NSURLErrorDomain Code=-1005 "网络连接已中断。” Http请求报错

最近内测的时候有收到一个有规律的报错请看一下返回, Error Domain=NSURLErrorDomain Code=-1005 "网络连接已中断。" UserInfo={_kCFStreamErrorCodeKey=57, NSUnderlyingError=0x282019fe0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(nul...

sky_long_fly的专栏 2万+

智能问数系统的完整技术栈与实现逻辑

提取并增强数据库 Schema(含业务语义)选择 LLM(开源 qwen2 / 商业 GPT-4o)构建 RAG 向量库(存储历史问法)实现 SQL 安全校验与权限控制添加结果自然语言解释 + 可视化部署到只读数据库环境🔑核心原则“先保证安全,再追求智能”—— 一个能生成错误 SQL 的智能问数系统,比没有更危险。

我们的征途是星辰大海 1617

【Unity】编译IOS报错:NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask(Code=1022)

iOS9引入了新特性AppTransportSecurity(ATS)。详情AppTransportSecurity(ATS)新特性要求App内访问的网络必须使用HTTPS协议。但是我们的项目使用的是HTTP协议,使用私有加密方式保证数据安全。某项目需要打包IOS,在打包过程中遇到了很多问题,以下是网络请求数据时报错。HTTP与HTTPS区别。...

weixin_42186644的博客 3160

多仓智能订单路由与动态优化方案设计

现在有很多商家会有多个仓库,并分布在不同的城市中,当用户下单后会根据商品库存及订单信息将订单分配到对应的仓库进行发货,如就近原则,本期基于多仓库设计一套订单路由方案,包含核心逻辑、规则优先级和实施方案,适用于多仓协同的订单自动分配场景

14年产品经理老兵,想把自己的经验及总结分享给大家,只讲思路及实操,不讲废话 2477

零差云控关节模组:EtherCAT+preempt-RT实现微秒级同步

关节模组是协作机器人、外骨骼与高精度服务机器人的核心执行单元,其性能瓶颈常在于多轴运动的时序一致性与实时闭环能力。实现‘零差’同步依赖于确定性通信(如EtherCAT)与硬实时操作系统支持(如Linux preempt-RT),前者保障指令与状态在微秒级时间戳下全局对齐,后者消除内核调度抖动,使PID控制、电流采样、编码器反馈等关键路径具备纳秒级可预测性。技术价值体现在相位偏差<±0.01°、端到端控制周期稳定1ms、连续运行温漂<±1.2℃等工程指标,广泛应用于力控装配、康复训练、远程遥操作等对动态精度与

weixin_34192816的博客 1197

iOS9中关于 NSURLSession/NSURLConnection HTTP load failed 的解决办法

最近为了新的存管app上线,忙了近一个月,重新过了一段996的日子,今天终于可以喘口气,继续更新博客了。本文记录一下在iOS 9中发送https请求遇到的问题及解决办法,希望通过本文,可以对ATS 的配置有一个更深入的了解。 问题描述 在开发app时,遇到了在iOS 9中发送https请求报错...

chenhui3831的博客 830

LVGL hal indev(porting evdev)

LVGL中对输入设备的管理是单例实现的,而在Linux的输入设备是多个的,所以需要对其进行改造成多例实现。

Bigan(安)的博客 3345

swift之URLSession的使用

URLSession是一个可以响应发送或者接受HTTP请求的关键类,可以通过URLSessionConfiguration类新建URLSession实例。有以下三种方式:URLSessionConfiguration.default默认configuration实例创建方式,使用硬盘上持久化全局缓存、证书(credential)和cookie的存储对象URLSessionConfiguration...

代码解释生活 9139

【skill】漫剧 AI 视频创作的知识库 + API 调用手册

方案适用场景在对话中使用,自动触发注入到任何 LLM(Cursor/Windsurf/Claude API)Python 模块集成到自动化管线/批量生成GitHub 又限速了,不过前几轮搜到的已经够用了。根据搜索结果,结合已分析过的项目,给你整理完整对比 🐮。

突围 978

YOLOv11改进 | 模型知识蒸馏篇 | 利用模型蒸馏改进YOLOv11进行无损涨点 | 在线蒸馏 (附代码 + 完整文件 + 解析教程)

这篇文章给大家带来的最新改进是模型的蒸馏,利用教师模型指导学生模型从而进行模型的涨点,本文的内容不仅可以用于论文中,在目前的绝大多数的工作中模型蒸馏是一项非常重要的技术,所以大家可以仔细学习一下本文的内容,本文从YOLOv11的项目文件为例,进行详细的修改教程,文章内包括完整的修改教程,针对小白我出了视频修改教程,如果你还不会我提供了修改后的文件大家直接运行即可,所以说不用担心不会适用!模型蒸馏真正的无损涨点,蒸馏你只看这一篇文章就足够了,本文内容为在线蒸馏教程,之前的文章为离线蒸馏!

Snu77的博客 2667

ios an ssl error has occurred and a secure

将电脑的日期时间设置正确,点击xcode的fix issue

wangwei-bocs-kunshan 2653

突破限制:巧用Azure OpenAI,畅玩Gemini模型

通过 Azure OpenAI 服务这一巧妙的途径,间接调用 Gemini 模型,打破网络限制的壁垒。本文将详细介绍这一方法,无论你是人工智能领域的新手,还是经验丰富的开发者,都能从中获取实用的技巧,轻松开启 Gemini 模型的探索之旅

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 180

ios7.1发布企业证书测试包的问题

关于升级了ios7.1之后发布企业版证书的测试包不能下载的问题,这个苹果也挺坑的,什么都不说,也不警告一下,直接就不能用了 用xcode的organizer里面的console里发现安装的时候提示这个: <Warning>: [ERROR]: Cannot load non-https manifest URL: http://192.168.1.36/kj.plist<...

weixin_30521649的博客 246

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

对于运营商劫持导致客户端域名解析出错,未能找到使用指定主机名的服务器, 请求超时,无法连接到服务器的一些思考

目前客户端直接使用域名访问的服务器。有些地区会出现无法连接到指定域名的服务器,这种类似的报错。 如果创建一个数组 这个数组里放域名对应的所有ip地址,每次启动客户端从这些ip随机选择一个访问,但当有的服务器ip更换后会出错。如果这样写,生产上出现这种问题会是我们客户端的问题。如下图 如果把域名也加在这个数组里,虽然出错几率会小一点,但出现这种问题会是我们客户端的问题。如下图 ...

qq_15509071的博客 2434

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

iOS开发网络篇 一一 NSURLSessionDownloadTask实现文件下载

NSURLSessionDownloadTask文件下载 和 NSURLConnection 下载的区别: 使用NSURLSessionDownloadTask任务来下载文件,不需要保存到沙盒中,downloadTaskWithRequest:comp 方法会自动将请求的数据,保存到沙盒中. 所以不需要手动将下载的数据写入到沙盒中. 知识点:  1. 使用block

Guizy 4603

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

NSURLSessionDownloadTask (开始,暂停,继续,取消下载)

这里面使用代理的方法发送请求 @property(nonatomic,strong) NSURLSessionDownloadTask *downTask; @property(nonatomic,strong) NSData *resumData; 开始下载 1.确定URL NSURL *url = [NSURL URLWithString:@""]; 2.创建请求对象 NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; 3

weixin_44729579的博客 1829

LeanCloud 三至四月变化

产品动态文件智能审核功能上线随着监管环境的变化,对于 UGC 内容,特别是图片的审核是一个非常广泛的需求。为此我们特别在「文件存储」中加入了智能审核的功能。开发者可以手动选择对某一时间区间的所有文件进行审核,也可以开启自动审核开关,对所有新上传的文件进行审核。文件在审核通过之前是不可见状态。开发者可以在「数据存储」-「文件」中看到,右侧增加了一个「文件审核」的页面,并且「...

LeanCloud通讯 609

NSURLSession使用NSURLSessionDownloadTask实现大文件下载,监听下载进度

感觉到法国 感受到附近开个户口登记 #import "ViewController.h" @interface ViewController ()<NSURLSessionDownloadDelegate> @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end @im...

a745050的博客 476

IOS开发之——下载-NSURLSession断点续传(07)

一 概述 NSURLConnection通过设置forHTTPHeaderField:@"Range"实现断点续传 本文介绍NSURLSession通过downloadTaskWithResumeData实现断点续传 二 NSURLSession实现断点续传的过程 界面上添加一个开始/暂停下载按钮,控制开始及暂停,点击按钮进行状态取反 开始下载包含了:从0开始下载和暂停后继续下载两种状态 从0开始下载时,NSURLSession通过downloadTaskWithURL执行下载操作,并回调NSURL

我的博客 941

iOS 文件下载:使用 NSURLSession 实现高效下载(一)

在 iOS 开发过程中,文件下载功能广泛应用于各种场景:从下载用户上传的文档、媒体文件,到提供应用更新包等。这些操作在现代应用中变得越来越常见,因此掌握如何通过高效、稳定的方法进行文件下载显得尤为重要。 本篇博客将介绍如何使用 NSURLSession 实现文件下载,并详细分析下载文件的步骤与细节,帮助开发者快速掌握这一常见功能。

qq_43673244的博客 1861

NSURLSession解决下载中的进度跟进问题——通过实现NSURLSessionDownloadDelegate协议中的回调方法...

使用NSURLSession解决下载中的进度跟踪问题,大致步骤如下: 第一步:网址转义。因为网址中如果有中文的话是不可以被服务器识别的。所以要对其进行转义。需要注意的是:下载一般都是GET请求 只有GET请求需要对网址进行转义,POST请求是不需要转义的。使用的转义方法如下: - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSS...

iteye_18817的博客 561

URLSession 生命周期

URLSession的生命周期 你可以有两种方法使用NSURLSession的api:一种是用系统提供的代理,一种是用自定义的代理。一般情况下,下列情况必须使用你自定义的代理: 1.当你的app不再运行的时候,在后台下载或者上传数据 2.执行自定义的认证 3.执行自定义的SSL证书认证 4.决定一个传输是否应该下载到磁盘还是根据服务器返回的MIME类型进行展示 5.用流作为请求体上传数

wulinan_wln的博客 966

ios 使用NSURlSession 下载文件并且使用进度条进行文件下载进度读取以及打开附件(word,excel,ppt,pdf)显示

ios 使用NSURlSession 下载文件并且使用进度条进行文件下载进度读取以及打开附件(word,excel,ppt,pdf)显示 话不多说,直接写代码了     NSURLSession * session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionCo

georgehenrywilliam的博客 1384

iOS9 https改成http

NSAppTransportSecurity             NSAllowsArbitraryLoads

王正魁 767

真机调试报错error ==Error Domain=NSURLErrorDomain Code=-1009 "似乎已断开与互联网的连接。"

真机调试报错error ==Error Domain=NSURLErrorDomain Code=-1009 "似乎已断开与互联网的连接。" 请注意,错误代码是-1009,网上关于网络链接查询错误代码的网站很多,查询一下,会发现 -1009 kCFURLErrorNotConnectedToInternet NSURLErrorNotConnectedToInternet “The

MinggeQingchun的博客 2万+
上一篇: iOS_使用NSURLSessionDataDelegate的代理方法下载数据
下一篇: Xcode_代码段
CaoYuan_CIKU
博客等级 码龄11年 40粉丝 58原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值