Skip to content

Commit

Permalink
Use single instance for Core Telephony network info
Browse files Browse the repository at this point in the history
  • Loading branch information
ghugues committed Feb 6, 2021
1 parent 221490e commit 90e9552
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ATInternetTracker/Sources/TechnicalContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,19 @@ class TechnicalContext: NSObject {
}
}

#if os(iOS) && canImport(CoreTelephony) && !targetEnvironment(simulator)
private static let telephonyInfo = CTTelephonyNetworkInfo()
#endif

/// Carrier
@objc class var carrier: String {
get {
#if os(iOS) && canImport(CoreTelephony) && !targetEnvironment(simulator)
let networkInfo = CTTelephonyNetworkInfo()
var provider : CTCarrier? = nil
if #available(iOS 12, *) {
provider = networkInfo.serviceSubscriberCellularProviders?.values.first
provider = telephonyInfo.serviceSubscriberCellularProviders?.values.first
} else {
provider = networkInfo.subscriberCellularProvider
provider = telephonyInfo.subscriberCellularProvider
}

if let optProvider = provider {
Expand Down Expand Up @@ -546,8 +549,7 @@ class TechnicalContext: NSObject {
} else if(optReachability.currentReachabilityStatus == ATReachability.NetworkStatus.notReachable) {
return ConnexionType.offline
} else {
#if os(iOS) && canImport(CoreTelephony)
let telephonyInfo = CTTelephonyNetworkInfo()
#if os(iOS) && canImport(CoreTelephony) && !targetEnvironment(simulator)
var radioType : String? = nil
if #available(iOS 12, *) {
radioType = telephonyInfo.serviceCurrentRadioAccessTechnology?.values.first
Expand Down

0 comments on commit 90e9552

Please sign in to comment.