Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use single instance for Core Telephony network info #111

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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