field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraCameraAccess.swift (1678B)


      1 import RadrootsKit
      2 
      3 enum TeraCameraAccess: Sendable, Equatable, CaseIterable {
      4   case authorized, notDetermined, denied, restricted, unavailable
      5 
      6   static func current() -> Self {
      7     switch RadrootsApplePermissionStatusAdapters.live.cameraStatus() {
      8     case .authorized: .authorized
      9     case .notDetermined: .notDetermined
     10     case .denied: .denied
     11     case .restricted: .restricted
     12     default: .unavailable
     13     }
     14   }
     15 
     16   var canCapture: Bool {
     17     self == .authorized || self == .notDetermined
     18   }
     19 
     20   var label: String {
     21     switch self {
     22     case .authorized: "Ready"
     23     case .notDetermined: "Permission requested when used"
     24     case .denied: "Access denied"
     25     case .restricted: "Restricted on this device"
     26     case .unavailable: "Unavailable"
     27     }
     28   }
     29 
     30   var guidance: String {
     31     switch self {
     32     case .authorized: "Camera access is available."
     33     case .notDetermined: "Camera access is requested only when you choose Camera."
     34     case .denied: "Camera access is off. You can enable it in Settings, then check access again."
     35     case .restricted: "Camera access is restricted on this device. A device administrator or parental controls may manage this restriction."
     36     case .unavailable: "A camera is unavailable on this device."
     37     }
     38   }
     39 }
     40 
     41 struct TeraAddMediaSupport: Sendable, Equatable {
     42   let library: Bool
     43   let camera: Bool
     44   let cameraAccess: TeraCameraAccess
     45 
     46   init(library: Bool, camera: Bool, cameraAccess: TeraCameraAccess = .authorized) {
     47     self.library = library
     48     self.camera = camera && cameraAccess.canCapture
     49     self.cameraAccess = camera ? cameraAccess : .unavailable
     50   }
     51 
     52   static let unavailable = Self(library: false, camera: false)
     53 }