Skip to content

Latest commit

 

History

History
14 lines (10 loc) · 757 Bytes

File metadata and controls

14 lines (10 loc) · 757 Bytes

How to make a network request wait for an internet connection

Set to true waitsForConnectivity property to make network requests wait for a viable internet connection before starting. This is useful in scenarios with intermittent connectivity. timeoutIntervalForResource specifies the maximum time (in seconds) a resource request should take, once it begins. In our example, we set it to 300 seconds, ensuring that downloads don't drag on indefinitely once they've started.

let config = URLSessionConfiguration.default
config.waitsForConnectivity = true
config.timeoutIntervalForResource = 300 // in seconds
let session = URLSession(configuration: config)

Reference

YouTube 👀