How to check for internet connectivity using NWPathMonitor
Apple’s Network framework provides a number of useful classes for working with network data, including one specifically designed to monitor network accessibility: NWPathMonitor
. If you ever used Apple’s older Reachability system, NWPathMonitor
replaces it fully.... Continue Reading >>
How to create a peer-to-peer network using the multipeer connectivity framework
The MultipeerConnectivity
framework is designed to allow ad hoc data transfer between devices that are in close proximity. The connection is started managed for you by iOS, but you're responsible for presenting useful interface to your users and for understanding the data that is being sent and received.... Continue Reading >>
How to download files with URLSession and downloadTask()
URLSession
is designed to make network transfers as easy as possible, and a great example of that is its downloadTask
()` method. This fetches the contents of a URL you specify, saves it to a local file, then calls a completion handler so you can manipulate the file – all in one.... Continue Reading >>
How to make a network request wait for an internet connection using waitsForConnectivity
If you use URLSession
to make a data task while the user has no internet connection, your request will fail immediately and report an error. However, if you create your session with the waitsForConnectivity
configuration option set to true, then the system will automatically wait some time to see if connectivity becomes available before trying the request.... Continue Reading >>
How to support low data mode networking using allowsConstrainedNetworkAccess
iOS lets users enable Low Data Mode for any cellular or WiFi connection, which signals to apps that they should be careful how much data they use. This might mean downloading lower-resolution images, it might mean disabling prefetching, or some other way of cutting down on bandwidth use.... Continue Reading >>
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift.
Link copied to your pasteboard.