Is there a way to check if the internet connection is available using Swift?
I know there are many third party libraries to do this but they are all written in Objective-C. I'm looking for a Swift alternative.
Is there a way to check if the internet connection is available using Swift?
I know there are many third party libraries to do this but they are all written in Objective-C. I'm looking for a Swift alternative.
In Swift 4 Working
Since sendSynchronousRequest is deprecated, I tried this but 'return Status' was called before the response had finished.
This answer works well though, Check for internet connection with Swift
Here's what I tried anyway:
I give you better way...
You must create a class with this code
And then you can check internet connection anywhere in your project using this code:
Very easy!
*This way is based on Vikram Pote answer!
SWIFT 3: Checks for wifi and internet connection:
USAGE:
For Swift 3.1 (iOS 10.1)
If you want to make the distinction between the network-type (i.e. WiFi or WWAN):
You can use:
Here is the entire Reachability-Class that distinguished between network-types:
SWIFT 3: Check 3G & Wi-Fi connection