Last active
November 3, 2019 07:37
-
-
Save PH9/fd93ba2dfea3e5cda8f332c5d313a17a to your computer and use it in GitHub Desktop.
Check is connected to WiFi
This file contains hidden or 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
// https://developer.apple.com/library/archive/samplecode/Reachability/Introduction/Intro.html | |
func isConnectToWiFi() throws -> Bool { | |
guard let reachability = Reachability.forInternetConnection() else { | |
throw ReachabilityError.cannotCreateReachability | |
} | |
// 0 is not reachable | |
// 1 is WiFi | |
// 2 is Cellular | |
guard reachability.currentReachabilityStatus() == .init(1) else { | |
return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment