Fetching Network Data
There are actually lots of APIs in iOS that can download data from a network connection. We’re going to focus on one that is the most useful for our current app and is the preferred networking API for most use cases: the URLSession. Like its name suggests, it’s a class for interacting with a URL for some period of time.
It’s also very flexible: URLSession can download or upload data, can work with password-protected resources, can download to disk or store in memory, and caches data it has already fetched (provided the server indicates that data is still valid). With proper care and feeding, a URLSession can download data while the app is in the background, so the app will have fresh content when foregrounded again.
Get iOS 10 SDK Development, 1st Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.