• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ios > timeoutIntervalForRequesttimeoutIntervalForResource有什么区别

timeoutIntervalForRequesttimeoutIntervalForResource有什么区别

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-05

佚名通过本文主要向大家介绍了timeout interval,readintervaltimeout,request timeout,408 request timeout,steamrequest timeout等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: timeoutIntervalForRequest timeoutIntervalForResource 有什么区别
描述:

NSURLSessionConfiguration中有两个超时设置,一个叫timeoutIntervalForRequest 另一个是timeoutIntervalForResource,这两个有什么不同?一般在何种情况下设置?


解决方案1:

下面的这段文字:参考这里
timeoutIntervalForRequest 和 timeoutIntervalForResource指定了请求以及该资源的超时时间间隔。许多开发人员试图使用timeoutInterval去限制发送请求的总时间,但这误会了timeoutInterval的意思:报文之间的时间。timeoutIntervalForResource实际上提供了整体超时的特性,这应该只用于后台传输,而不是用户实际上可能想要等待的任何东西。

自己测试和理解

在一定的情况下(timeoutInterval,timeoutIntervalForResource,timeoutIntervalForRequest)这三个值均可以触发请求超时。

分两种情况理解,即有没有给NSURLReaqust设置timeoutInterval。

1.如果设置了NSURLRequest timeoutInterval:
忽略timeoutIntervalForRequest设置,以timeoutIntervalForResource、timeoutInterval较小的值为超时时间。

2.没有设置NSURLRequest timeoutInterval:
以timeoutIntervalForRequest、timeoutIntervalForResource较小的值为超时时间,并不是Request timeoutInterval的默认60s。

NSURLRequest和SessionConfiguration都不设置使用默认值60s超时。

background session模式下上传下载忽略掉timeoutIntervalForRequest和timeoutInterval的设置
使用timeoutIntervalForResource

NSURLRequest
timeoutInterval-(默认60s)

SessionConfiguration
timeoutIntervalForRequest- (默认60s)
timeoutIntervalForResource- (默认7天)

@property NSTimeInterval timeoutIntervalForRequest;
Description
The timeout interval to use when waiting for additional data.
This property determines the request timeout interval for all tasks within sessions based on this configuration. The request timeout interval controls how long (in seconds) a task should wait for additional data to arrive before giving up. The timer associated with this value is reset whenever new data arrives. When the request timer reaches the specified interval without receiving any new data, it triggers a timeout.
The default value is 60.
Important
Any upload or download tasks created by a background session are automatically retried if the original request fails due to a timeout. To configure how long an upload or download task should be allowed to be retried or transferred, use the timeoutIntervalForResource property.
AvailabilityiOS (7.0 and later), macOS (10.9 and later), tvOS (9.0 and later), watchOS (2.0 and later)

@property NSTimeInterval timeoutIntervalForResource;
Description
The maximum amount of time that a resource request should be allowed to take.
This property determines the resource timeout interval for all tasks within sessions based on this configuration. The resource timeout interval controls how long (in seconds) to wait for an entire resource to transfer before giving up. The resource timer starts when the request is initiated and counts until either the request completes or this timeout interval is reached, whichever comes first.
The default value is 7 days.
AvailabilityiOS (7.0 and later), macOS (10.9 and later), tvOS (9.0 and later), watchOS (2.0 and later)

@property NSTimeInterval timeoutInterval;
Description
The receiver’s timeout interval, in seconds.
If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out. The default timeout interval is 60 seconds.
As a general rule, you should not use short timeout intervals. Instead, you should provide an easy way for the user to cancel a long-running operation. For more information, read Designing for Real-World Networks in Networking Overview.
AvailabilityiOS (8.0 and later), macOS (10.10 and later), tvOS (9.0 and later), watchOS (2.0 and later)

正常情况下设置timeoutIntervalForRequest(根据文档我觉得可以理解为请求的默认超时时间)和NSURLRequest timeoutInterval(针对单个请求设置超时时间)

特殊情况下(background session模式下上传、下载)设置timeoutIntervalForResource


分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • timeoutIntervalForRequesttimeoutIntervalForResource有什么区别

相关文章

  • 2017-06-05 SwiftBool解包判断问题
  • 2017-06-05 UITableViewCell中嵌套UICollectionView,希望前者的高度根据后者的高度而改变
  • 2017-06-05 iOS开发,UI设计师给的750的设计图,如何适配各种尺寸的屏幕?
  • 2017-06-05 微信网页版朋友圈iOS分享多张图片到微信朋友圈
  • 2017-06-05 关键字搜索怎么写
  • 2017-06-05 我用AVPlayer播放本地视频在切换前后台状态的时候有几率会先出现启动图片再跳回播放界面是为啥?
  • 2017-06-05 触摸屏控制器A控制器跳转B控制器,B黑屏?
  • 2017-06-05 iOS蓝牙链接打印机如何将图片转化为打印机可以识别的数据?
  • 2017-06-05 官方敢不敢出个同时包含PLPlayerKit和PLMediaStreamingKit的demo
  • 2017-06-05 关于UISearchController的一个问题

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 开发手机BLE(低功耗蓝牙)App,有什么跨平台开发工具吗?
    • AFN3x怎么做网络依赖?
    • ios开发,我们很多时候需要针对不同渠道来打包,可能渠道很多,需要生成大量的ipa包,请问苹果对打包数量有限制吗
    • iOS基础控件小白提问,ios如何签名?
    • ios是什么iOS抽象工厂什么时候用
    • 淘宝商城和淘宝网的区别淘宝的我的设计怎么实现的?
    • iosswift多个界面,viewcontroller应该怎么写呢?纯代码
    • avplayer音频与webview里面的播放视频声音同时播放了,怎么解决啊,各位大神。
    • swift3Pruchse無法取得產品資訊
    • 手机客户端开发开发iOSApp是否需要有后端?

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有