Last active
November 3, 2019 07:09
-
-
Save PH9/38b7da299b244559db6c328e53373cfa to your computer and use it in GitHub Desktop.
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
import CoreTelephony | |
func getNetworkType() throws -> String { | |
let networkInfo = CTTelephonyNetworkInfo() | |
guard let accessTechnology = networkInfo.currentRadioAccessTechnology else { | |
throw ReachabilityError.cannotGetCurrentRadioAccessTechnology | |
} | |
return networkStringToReadableString(accessTechnology) | |
} | |
func networkStringToReadableString(_ networkString: String) -> String { | |
switch networkString { | |
case CTRadioAccessTechnologyGPRS, | |
CTRadioAccessTechnologyEdge, | |
CTRadioAccessTechnologyCDMA1x: | |
return "2G" | |
case CTRadioAccessTechnologyWCDMA, | |
CTRadioAccessTechnologyHSDPA, | |
CTRadioAccessTechnologyHSUPA, | |
CTRadioAccessTechnologyCDMAEVDORev0, | |
CTRadioAccessTechnologyCDMAEVDORevA, | |
CTRadioAccessTechnologyCDMAEVDORevB, | |
CTRadioAccessTechnologyeHRPD: | |
return "3G" | |
case CTRadioAccessTechnologyLTE: | |
return "4G" | |
default: | |
return networkString | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment