Skip to content

Commit ae39eea

Browse files
committed
Hide cellular toggle on non-cellular devices
Many iPads don’t have a cellular connection. It’s a little confusing to show the cellular toggle when it doesn’t apply. Unfortunately, there’s no good (undeprecated) API for checking this. I’ve used an approach of listing the network interfaces and looking for the cellular one, but it’s undocumented and might not always work. OTOH, this isn’t a critical feature, so we can keep an eye on it.
1 parent 0f3a835 commit ae39eea

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Modules/Sources/PointOfSale/Presentation/Settings/POSSettingsLocalCatalogDetailView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ struct POSSettingsLocalCatalogDetailView: View {
1818
ScrollView {
1919
VStack(spacing: POSSpacing.medium) {
2020
catalogStatus
21-
managingDataUsage
21+
if viewModel.deviceHasCellularCapability {
22+
managingDataUsage
23+
}
2224
manualCatalogUpdate
2325
}
2426
.padding(.horizontal, POSPadding.medium)

Modules/Sources/PointOfSale/Presentation/Settings/POSSettingsLocalCatalogViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import CocoaLumberjackSwift
22
import Yosemite
33
import Foundation
44
import Storage
5+
import WooFoundation
56

67
@Observable
78
final class POSSettingsLocalCatalogViewModel {
@@ -11,6 +12,7 @@ final class POSSettingsLocalCatalogViewModel {
1112

1213
private(set) var isLoading: Bool = false
1314
private(set) var isRefreshingCatalog: Bool = false
15+
let deviceHasCellularCapability: Bool = CellularCapabilityChecker.deviceHasCellularCapability()
1416

1517
var catalogRefreshError: POSIdentifiableErrorState? = nil
1618

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Darwin
2+
3+
public struct CellularCapabilityChecker {
4+
public static func deviceHasCellularCapability() -> Bool {
5+
var addrs: UnsafeMutablePointer<ifaddrs>?
6+
guard getifaddrs(&addrs) == 0 else { return false }
7+
defer { freeifaddrs(addrs) }
8+
9+
var cursor = addrs
10+
while let addr = cursor {
11+
guard let namePtr = addr.pointee.ifa_name else {
12+
cursor = addr.pointee.ifa_next
13+
continue
14+
}
15+
16+
let name = String(cString: namePtr)
17+
// This isn't a great check, but the alternatives are deprecated, and apparently it's commonly used.
18+
// pdp_ip0 is the first cellular interface – it's not present if there's no cellular hardware.
19+
if name == "pdp_ip0" {
20+
return true
21+
}
22+
cursor = addr.pointee.ifa_next
23+
}
24+
return false
25+
}
26+
}

0 commit comments

Comments
 (0)