LocationTracker: - isPaused, pausedAt, accumulatedPausedSeconds - pause()/resume()/restore() Methoden - effectiveElapsedSeconds rechnet Pausen raus - restore() für nach App-Crash: Offline-Lücke wird als Pause gezählt ActiveWalk @Model (SwiftData): - startedAt, lastUpdate, pausedAt, accumulatedPausedSeconds, pointsData - Container in BanYaroGoApp registriert TrackingView: - Persistenz alle 5s via Timer - confirmationDialog beim Erscheinen wenn ActiveWalk vorhanden: Fortsetzen / Jetzt speichern / Verwerfen - Pause/Resume-Button + Stop-Button - Floating Kamera-Button rechts unten - Foto-Counter in der Stats-Karte - Pause-Badge oben links bei Pause CameraPicker: UIImagePickerController-Wrapper (Fallback auf Library im Simulator). FinishWalkSheet: initialPhotos: [Data] für Kamera-Fotos während Tour. RouteDetailView: PhotosPicker zum Hinzufügen von Fotos zu bestehender Tour, sequentieller Upload mit Progress, Detail wird nach Upload refreshed. NSCameraUsageDescription in BanYaroGo-Info.plist.
46 lines
1.7 KiB
Swift
46 lines
1.7 KiB
Swift
import SwiftUI
|
|
import UIKit
|
|
|
|
/// Native camera capture via UIImagePickerController, wrapped for SwiftUI.
|
|
/// Falls back to the photo library on the simulator where no camera exists.
|
|
struct CameraPicker: UIViewControllerRepresentable {
|
|
let onCapture: (Data) -> Void
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
func makeCoordinator() -> Coordinator { Coordinator(self) }
|
|
|
|
func makeUIViewController(context: Context) -> UIImagePickerController {
|
|
let picker = UIImagePickerController()
|
|
picker.delegate = context.coordinator
|
|
if UIImagePickerController.isSourceTypeAvailable(.camera) {
|
|
picker.sourceType = .camera
|
|
picker.cameraCaptureMode = .photo
|
|
} else {
|
|
// Simulator has no camera — let testing still work via library.
|
|
picker.sourceType = .photoLibrary
|
|
}
|
|
return picker
|
|
}
|
|
|
|
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}
|
|
|
|
final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
|
let parent: CameraPicker
|
|
init(_ parent: CameraPicker) { self.parent = parent }
|
|
|
|
func imagePickerController(
|
|
_ picker: UIImagePickerController,
|
|
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
|
|
) {
|
|
if let image = info[.originalImage] as? UIImage,
|
|
let data = image.jpegData(compressionQuality: 0.9) {
|
|
parent.onCapture(data)
|
|
}
|
|
parent.dismiss()
|
|
}
|
|
|
|
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
|
|
parent.dismiss()
|
|
}
|
|
}
|
|
}
|