Compare commits

...

3 commits

Author SHA1 Message Date
a6ba88803c Merge pull request 'fix: back button bounces user back into selected business' (#31) from schwifty/fix-back-button-bounce into main 2026-03-22 22:32:12 +00:00
81d4cad030 fix: back button bounces user right back into selected business
When tapping Back from ScanView, BusinessListView remounts and .task fires
loadBusinesses() which sees AppPrefs.lastBusinessId still set — immediately
re-navigating into the same business. Fix: clear lastBusinessId on back,
and add skipAutoNav flag to also prevent single-business auto-select from
firing when user explicitly navigated back.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 21:47:45 +00:00
f60c70f32a fix: QR scanner crash — missing NSCameraUsageDescription in Info.plist
The app crashed immediately when tapping QR scan because the Info.plist
was missing the required NSCameraUsageDescription key. iOS kills the app
with EXC_BAD_INSTRUCTION when camera access is requested without it.

Also fixes:
- Flash toggle could SIGABRT if lockForConfiguration failed (try? + unconditional unlock)
- Camera setup now logs errors instead of silently failing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 21:45:10 +00:00
4 changed files with 40 additions and 15 deletions

View file

@ -14,6 +14,9 @@ final class AppState: ObservableObject {
@Published var token: String?
@Published var userId: String?
/// When true, skip auto-navigation in BusinessListView (user explicitly went back)
var skipAutoNav = false
init() {
// Restore saved session
if let saved = SecureStorage.loadSession() {
@ -36,6 +39,8 @@ final class AppState: ObservableObject {
}
func backToBusinessList() {
AppPrefs.lastBusinessId = nil
skipAutoNav = true
currentScreen = .businessList
}

View file

@ -22,6 +22,8 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>Payfrit Beacon needs camera access to scan QR codes on beacon labels for provisioning.</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Payfrit Beacon needs Bluetooth to detect and configure nearby beacons.</string>
<key>NSBluetoothPeripheralUsageDescription</key>

View file

@ -94,6 +94,8 @@ struct BusinessListView: View {
let list = try await APIClient.shared.listBusinesses(token: token)
businesses = list
// Skip auto-navigation if user explicitly tapped Back
if !appState.skipAutoNav {
// Auto-navigate if only one business (like Android)
if list.count == 1, let only = list.first {
appState.selectBusiness(only)
@ -106,6 +108,8 @@ struct BusinessListView: View {
appState.selectBusiness(last)
return
}
}
appState.skipAutoNav = false
} catch let e as APIError where e.errorDescription == APIError.unauthorized.errorDescription {
appState.logout()
} catch {

View file

@ -241,17 +241,31 @@ final class CameraPreviewUIView: UIView {
func setFlash(_ on: Bool) {
guard let device = AVCaptureDevice.default(for: .video),
device.hasTorch else { return }
try? device.lockForConfiguration()
do {
try device.lockForConfiguration()
device.torchMode = on ? .on : .off
device.unlockForConfiguration()
} catch {
NSLog("[QRScanner] Failed to set torch: \(error.localizedDescription)")
}
}
private func setupCamera() {
let session = AVCaptureSession()
session.sessionPreset = .high
guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back),
let input = try? AVCaptureDeviceInput(device: device) else { return }
guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else {
NSLog("[QRScanner] ERROR: No back camera available")
return
}
let input: AVCaptureDeviceInput
do {
input = try AVCaptureDeviceInput(device: device)
} catch {
NSLog("[QRScanner] ERROR: Failed to create camera input: \(error.localizedDescription)")
return
}
if session.canAddInput(input) {
session.addInput(input)