When I try to check for an internet connection on my iPhone I get a bunch of errors. Can anyone help me to fix this?
The code:
import Foundation
impo
Although it does not directly answers your question, I would like to mention Apple recentely had this talk:
https://developer.apple.com/videos/play/wwdc2018/714/
At around 09:55 he talks about doing this stuff you are asking about:
However, this has a few pitfalls:
The following points are some best practices according to Apple:
waitsForConnectivity
to true (https://developer.apple.com/documentation/foundation/urlsessionconfiguration/2908812-waitsforconnectivity)taskIsWaitingForConnectivity
(https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/2908819-urlsession). This is Apple's recommended way to check for connectivity, as mentioned in the video at 33:25.According to the talk, there shouldn't be any reason to pre-check whetever you got internet connection or not, since it may not be accurate at the time you send your request to the server.