Search code examples
swift3reachability

Check For Internet Connectivity In Swift


I am using Swift 3 and Xcode 8. All the other scripts and stuff online to do this all raise a lot of errors. How would I in a simple way make the app check for an Internet connection when it was launched and if it had one to continue and if it doesn't have a connection to show the user a popup saying so?

I am open to any suggestion.


Solution

  • The easiest way to check for internet connectivity is to use the iOS reachability api.

    It's available in the SystemConfiguration module.

    Objective-C Reachability Example

    A good example of using SCNetworkReachability in swift is found in the stack overflow answer:

    SCNetworkReachability in swift

    I hope this helps! Have a nice day!