NSURLSessionConfiguration timeoutIntervalForRequest doesn't seem to work with the background session

允我心安 提交于 2019-12-08 00:40:39

问题


The new timeout property of NSURLSessionConfiguration doesn't seem to work when the session is set to work in background (via backgroundSessionConfiguration call).

Anybody know if that's really the case?

Code snippet:

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:bgSessionConfigIdentifier];
sessionConfig.HTTPMaximumConnectionsPerHost = 1;
sessionConfig.timeoutIntervalForRequest = 60;

Do I need to do anything extra for the timeout to work?


回答1:


I just ran into similar problem, fixed it by using timeoutIntervalForResource instead of timeoutIntervalForRequest

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfigurationbackgroundSessionConfiguration:bgSessionConfigIdentifier];
sessionConfig.HTTPMaximumConnectionsPerHost = 1;
sessionConfig.timeoutIntervalForResource = 60;


来源:https://stackoverflow.com/questions/20505858/nsurlsessionconfiguration-timeoutintervalforrequest-doesnt-seem-to-work-with-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!