objccn / articles

Articles for objccn.io. objc.io的完整、准确、优雅的中文翻译版本
http://objccn.io/
2.11k stars 431 forks source link

NSURLSessionConfiguration 中的 discretionary属性的介绍问题 #439

Closed leavesster closed 7 years ago

leavesster commented 8 years ago

从 NSURLConnection 到 NSURLSession http://objccn.io/issue-5-4/ 介绍discretionary属性时,提到的:

allowsCellularAccess 和 discretionary 被用于节省通过蜂窝网络连接的带宽。对于后台传输的情况,推荐大家使用 discretionary 这个属性,而不是 allowsCellularAccess,因为前者会把 WiFi 和电源的可用性考虑在内。

在苹果文档中还指出,当文件非常大时,这个属性也会做出相应的推迟,必须要插上电源以后,才会继续。虽然原文没有,但是,是不是把这一点也写上比较好?

When transferring large amounts of data, you are encouraged to set the value of this property to YES. Doing so lets the system schedule those transfers at times that are more optimal for the device. For example, the system might delay transferring large files until the device is plugged in and connected to the network via Wi-Fi. The default value of this property is NO.

我的遭遇是,大概40多分钟的视频,会出现延迟下载。但是具体多大的文件,我也不清楚…… 以上是自己的遭遇,可能实际环境中,还有部分其他代码的影响,但是使用allowsCellularAccess为NO时的确是可以的。


还有就是当在后台时,该属性会自动设置认为是YES,而不是根据我们自行设置的值。不知道我有没有理解对,感觉这个也写上比较好。

For transfers started while your app is in the background, the system always starts transfers at its discretion—in other words, the system assumes this property is YES and ignores any value you specified.