Skip to content

Instantly share code, notes, and snippets.

@PH9
Last active November 3, 2019 07:37
Show Gist options
  • Save PH9/fd93ba2dfea3e5cda8f332c5d313a17a to your computer and use it in GitHub Desktop.
Save PH9/fd93ba2dfea3e5cda8f332c5d313a17a to your computer and use it in GitHub Desktop.
Check is connected to WiFi
// 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