Created
August 13, 2020 15:24
-
-
Save Coder-ACJHP/8b54dc2d9063562605265cca78d47143 to your computer and use it in GitHub Desktop.
Network connectivity checker, It can be used instead of Reachability.swift
This file contains 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
// | |
// 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