0

I am trying to send a URL request to the server by using URLSession.shared.dataTask.

When the network is unreachable, the log will show "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." and nothing will be sent without retry.

Is there any method I can use to re-send a URL request until the network is reachable?

Dennis
  • 37
  • 6
  • Are you trying a HTTP only connection? If so, since iOS 9, you have to manually add an entry to allow HTTP only inside of your info.plist. Apple's ATS defaults to HTTPS only, unless you override it. https://stackoverflow.com/questions/32631184/the-resource-could-not-be-loaded-because-the-app-transport-security-policy-requi – rustyMagnet Aug 26 '18 at 12:13

2 Answers2

0

You can send a new request in the body of the previous request's response, specifically in the error closure. A better practice is to use Reachability and send the request only whenever a network connection is available

https://github.com/ashleymills/Reachability.swift

0

Your answer is yes, you can use ReachabilitySwift to monitor network changes in your app and get notified and send URL request when it has access to wifi or cellular data

MohyG
  • 1,335
  • 13
  • 25