何时创建新的NSURLSession? [英] When to create new NSURLSession?
问题描述
重用NSURLSessions
的最佳实践是什么?据我所知,似乎只要不需要更改配置(超时,缓存策略等),就无需创建新的配置(因为您可以从中产生新的任务)./p>
那么可以将单个NSURLSession
重用于整个应用程序吗?每个域/端点?每个请求?
检出文档.尤其是"与大多数网络API一样,NSURLSession API是高度异步的."
您始终可以创建专门用于处理应用程序所有联网的联网类.因此,重用不仅是一种选择,而且还建议使用.
https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/
这里很好本教程解释了NSURLSession和NSULConnection之间的区别,以更好地了解其预期用途.
What is the best practices for reusing NSURLSessions
? From what I can tell, it seems that as long as the configuration (timeouts, caching policies, etc.) does not need to change, there is no need to create a new one (since you can spawn new tasks from it).
So can a single NSURLSession
be reused for an entire app? Per domain/endpoint? Per request?
Checkout the docs. Specifically "Like most networking APIs, the NSURLSession API is highly asynchronous."
You can always create a networking class that specifically handles all of your networking for the app. So reusing is not only an option but is also recommended.
https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/
Here is a pretty good tut that explains the differences between NSURLSession and NSULConnection for better understanding of it's intended usage.
这篇关于何时创建新的NSURLSession?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!