Skip to content

Instantly share code, notes, and snippets.

@Coder-ACJHP
Created August 13, 2020 15:24
Show Gist options
  • Save Coder-ACJHP/8b54dc2d9063562605265cca78d47143 to your computer and use it in GitHub Desktop.
Save Coder-ACJHP/8b54dc2d9063562605265cca78d47143 to your computer and use it in GitHub Desktop.
Network connectivity checker, It can be used instead of Reachability.swift
//
// Connectivity.swift
// Test App
//
// Created by Onur Işık on 14.05.2020.
// Copyright © 2020 Onur Işık. All rights reserved.
//
// NOTE: This struct needs to Alomafire pod to work (Alomafire includes NetworkReachabilityManager)
struct Connectivity {
public enum ConnectionType: String {
case Wifi, Cellular, NotConnectied
}
static let sharedInstance = NetworkReachabilityManager()!
static var isConnectedToInternet: Bool {
return self.sharedInstance.isReachable
}
static func isConnectedToInternet(completionHandler: @escaping (ConnectionType) -> ()) {
if self.sharedInstance.isReachable {
if self.sharedInstance.isReachableOnEthernetOrWiFi {
completionHandler(.Wifi)
} else if self.sharedInstance.isReachableOnWWAN {
completionHandler(.Cellular)
}
} else {
completionHandler(.NotConnectied)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment