Networking with URLSession
Learn how to use URLSession, Apple's networking API, including when and how to use data, download and upload tasks, with or without a custom session delegate, and how the system manages background sessions and WebSockets. Leverage the Combine API and SwiftUI to take your networking to the next level. Updated for iOS 13 and Swift 5.2. By Brian Moakley.
Who is this for?
Intermediate developers. You should be comfortable with the Swift programming language and up to speed on the SwiftUI framework. You should also have some working knowledge of the Combine framework.
You'll start by getting an overview of concurrency then you'll learn how to make simple network requests. Later, you'll learn how to download and upload files and how to set up background sessions. Ultimately, you'll leverage the power of the Combine framework to make your requests.
Finally, you'll learn about authentication, Apple's Transport Security and reading and writing cookies.
Covered concepts
- URLSession Configuration
- URLSession Connections
- Downloading Files
- Uploading Data
- Pausing, Resuming and Canceling Data
- Showing Network Progress
- Simulating Different Network Speeds
- Vapor Framework
- Background Downloading
- WebSockets
- URLSession and Combine
- Authentication
- Application Transport Security
- Cookies
Part 1: Concurrency and DataTasks
Learn about the URLSession and how the framework evolved in the way that it did. Also learn about the course goals.
Get an overview of why concurrency is important and how ignoring it can create a terrible user experience.
In this episode, get a brief overview of the various options in iOS and see them in action.
This challenge will put your understanding of concurrency to the test by updating the user interface from an operation queue.
Learn the basics of Session Configuration and how you can use the configuration to modify your session's behavior.
This episode covers the basics of working with sessions and how to use session data tasks to fetch remote data.
Now that you have an idea of how to create a session, your challenge is to create your own session and fetch artwork from over the network.
Review the concepts covered in this part and preview the next part of the course.
Part 2: Downloading and Uploading
Now that you understand the data task, learn how to put the download task and upload task to use.
Working with tasks often means setting priorities and figuring out what to cache. This episode covers what you need to know.
In this episode, put the download task to use by downloading music from iTunes preview API.
Put your downloading skills to the test by downloading some album artwork and displaying it on the screen.
In this episode, learn how to display download progress as a file is downloaded.
You have lots of different tools to simulate poor network connections. This episode will show you a few of them.
This episode covers the process of pausing, canceling and resuming downloads.
Vapor is an open source server written entirely in Swift. In this episode, learn how to install the server.
Learn how to upload data to a local vapor instance.
This episode concludes the part on downloading and uploading, but things are just starting to get interesting
Part 3: Background Downloading and WebSockets
This episode introduces the concept of background downloading and WebSocket communication.
Learn about the background task, how to use one of them and then how to handle background events.
This episode gives you an overview of BSD sockets and explains how Apple's Networking framework works for you.
Use the new WebSocket task to connect a local Vapor server to send messages and then use them to create a chat server.
Review all the concepts covered in this part and then learn about upcoming topics.
Part 4: URLSession and Combine
Combine is a native reactive framework that released with iOS 13. Learn how URLSession has been updated to use it.
This episode provides an overview of the general concepts behind the Combine framework.
Learn how to use a data task with Combine and then how to access the data through a variety of operators.
With the use of Zip, learn how to group multiple requests together.
Learn how to make a urlrequest once another request has finished.
Put your Combine skills to the test by fetching a list of album titles and printing the results out to a list.
Learn how handle errors when something goes wrong during URLSession
This concludes this part on Combine but there's more to learn in the final part of this course.
Part 5: Authentication, ATS and Cookies
This final part of the course covers a variety of important topics that you will need to know when making network requests.
This episode covers the various different ways to provide authentication when working with URLSession.
iOS provides some important security mechanisms when making requests on iOS. This episode shows how ATS can affect your app.
Learn how read cookies and write cookies from a URLSession
In this challenge, learn print cookies from raywenderlich.com
This final episode concludes the course while providing several resources on where to learn more about URLSession.