RoomioScanSession
A single scan, from starting the camera to exporting the result.
final class RoomioScanSession
Overview
Create a session with startScan(config:) and show it in a RoomioScanView. Call start() to begin recording; the view’s own buttons let the user finish or exit the scan. Follow it through state and events, then call export() once it is RoomioScanState.finished.
The session is Observable: a SwiftUI view that reads state, isShowingOnboarding or isShowingDialog updates when they change. In UIKit, follow them with withObservationTracking.
The session is Identifiable, so you can present it with fullScreenCover(item:).
cancel()
Abandon the scan without saving it. state moves to RoomioScanState.cancelled; call close() afterwards. RoomioScanView calls this when the user confirms they want to exit, or leaves a sheet shown before the scan.
func cancel()
close()
Discard the session and release the camera, and delete the scan’s working files. An exported RoomioBundle is kept. The session is unusable afterwards, and state keeps how the scan ended.
func close()
events
Notifications from the scan, such as tracking changes and progress. Read with for await.
var events: AsyncStream<RoomioScanEvent> { get }
export()
Package the finished scan for upload. Call once state is RoomioScanState.finished, which comes a few seconds after stop() while the scan saves.
nonisolated(nonsending) func export() async throws -> RoomioBundle
Throws: RoomioError with exportFailed if the scan cannot be packaged.
isShowingDialog
Whether RoomioScanView is showing a sheet or dialog: a device check before the scan, the exit confirmation, or saying the scan failed or couldn’t be saved. Hide your own controls while it is.
var isShowingDialog: Bool { get }
isShowingOnboarding
Whether RoomioScanView is showing the onboarding before the scan. Hide your own controls while it is; it ends when the user finishes or skips it, and the camera starts then. Turn it off with showsOnboarding.
var isShowingOnboarding: Bool { get }
pause()
Pause the scan until resume(). The scan also pauses by itself when the app goes to the background, and resumes by itself when the app returns.
func pause()
resume()
Resume a scan paused with pause().
func resume()
scanId
Identifies the scan; quote it when contacting Roomio about it. Nil until start().
var scanId: String? { get }
start()
Start recording the scan. Call it when you show RoomioScanView: while the view shows the onboarding, recording begins once the user finishes or skips it.
func start()
Discussion
While Low Power Mode is on, the scan doesn’t start: the view shows a sheet asking the user to turn it off, whose only button cancels the session, and events reports RoomioScanEvent.failed(_:) with powerSaving. Likewise while the device is too low on storage (under 200 MB), with insufficientStorage, and while the battery is at 25% or less, with lowBattery. During a scan, each of them only shows a warning; the scan carries on.
When storage is low (under 3 GB) or the battery is under 50%, the view first asks the user whether to continue anyway. Continuing starts the scan; leaving moves state to RoomioScanState.cancelled, as exiting does.
When camera access is refused, the view shows a sheet whose buttons open your app’s page in Settings or cancel the session, and events reports RoomioScanEvent.failed(_:) with permissionDenied. Once the user allows access and returns to your app, the sheet closes and the scan starts.
startPreview()
Start the camera without recording.
func startPreview()
Discussion
Optional: start() starts the camera too. Call this before presenting RoomioScanView only if you want the camera preview live while your own pre-scan instructions are showing. Asks for camera access if your app hasn’t yet; if the user declines, RoomioScanView asks them to allow it in Settings (see permissionDenied).
state
The current state of the scan.
var state: RoomioScanState { get }
Discussion
The state can also change without a call from you, for example when the app goes to the background. After close() it stays as it was when you closed the session.
stop()
Finish recording. Call export() afterwards to get the result.
func stop() throws
Throws: RoomioError with notReady in the first few seconds of a scan.