Last active
April 7, 2023 21:15
-
-
Save LukeSmith16/9494a5bd6e57b4a66a8740508329f859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func downloadHighResImage() { | |
var request = URLRequest(url: URL(string: "highQualityImageURL")!) | |
// Trigger error in `session.dataTask` if user has low data mode enabled. | |
request.allowsConstrainedNetworkAccess = false | |
URLSession.shared.dataTask(with: request) { data, response, error in | |
if let error = error as? URLError, | |
error.networkUnavailableReason == .constrained { | |
// Download low res image which uses less data | |
downloadLowResImage() | |
} | |
// Logic... | |
}.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment