// The one place an app adds to or asks for the photo library. Left out of an app whose plist says nothing about// photos (`COTTON_NO_PHOTOS`, set by ios-spec-gate for Days): App Store processing refuses a binary that references// the Photos API without a photo library purpose string (ITMS-90683, 22 Nov 2026).#if !COTTON_NO_PHOTOSimportCottonKitimportPhotos/// The phone's camera roll, write-only — the ONE place a shot is added to the/// photo library, in the phone app and nowhere in the package, so a test/// bundle cannot reach it. Installed at launch into `LiveStores`; the Camera/// tool's `ShotPipeline` calls it after the shot is already in Cotton and only/// once the capability gate has said yes to adding. `LiveStoresSweepTests`/// holds the rule./// Not compiled into an app that may not write photos (`COTTON_NO_PHOTO_WRITES`: Cotton Albums' look-only build).#if !COTTON_NO_PHOTO_WRITESstructSystemCameraRoll: CameraRoll {func save(file: URL, kind: CaptureMediaKind) asyncthrows {tryawait PHPhotoLibrary.shared().performChanges { PHAssetCreationRequest.forAsset() .addResource(with: kind == .video ? .video : .photo, fileURL: file, options: nil) } }}#endif/// Photo library permission, read and asked: the whole library (`add == false`) or adding one picture.structSystemPhotoAccess: AccessAsking {let add: Boolfunc status() async -> CapabilityAccess {Self.access(PHPhotoLibrary.authorizationStatus(for: add ? .addOnly : .readWrite), add: add) }func ask() async -> CapabilityAccess {Self.access(await PHPhotoLibrary.requestAuthorization(for: add ? .addOnly : .readWrite), add: add) }/// **`limited` is a YES for adding one picture** (add-only access is not filtered by a selection) and a NO for/// reading the whole library, which is what a whole-library sync needs.staticfunc access(_ status: PHAuthorizationStatus, add: Bool) -> CapabilityAccess {switch status {case .authorized: return .authorizedcase .limited: return add ? .authorized : .deniedcase .notDetermined: return .notDeterminedcase .denied: return .deniedcase .restricted: return .restricted @unknown default: return .denied } }}#endif