Using NSURLSession API for network connections
The NSURLSession
is one of the greatest APIs that has been added to the iOS framework and is to be used in setting up connections between the app and the backend, and fetching contents from your server. In this section, we will talk in details (but not boring detail) about NSURLSession
: how to deal with it, and what kind of tasks it can do. We will build a demo project for this chapter and, in each section, we will add a feature related to the topic in the project.
Getting ready
With Apple, by default, NSURLSession
supports the following URL schemes:
File Transfer Protocol: (
ftp://
)Hypertext Transfer Protocol: (
http://
)Encrypted Hypertext Transfer Protocol: (
https://
)File URLs: (
file://
)Data URLs: (
data://
)
In the app, you can have multiple sessions, and each session can deal with a group of related data connections. Any kind of operation done via NSURLSession
is called a task, which is a subclass of an abstract class, called NSURLSessionTask
. We...