Skip to the page
Docs menu

Docs The three steps

Scan in your app

Put the Timbereye scanner in your own iOS or Android app with a publishable key. One configure call, one view.

Step 2 of 3: Scan. For teams adding scanning to their own iOS or Android app. By the end, your app scans into a group you created, or one it opens by your record id. With no mobile code, use the Timbereye app instead.

State. iOS: the scanner is in the Swift SDK (product Timbereye, Swift Package Manager).Android: the same scanner in the Kotlin SDK (sdk/kotlin, artifact com.timbereye:timbereye), not yet published: build from source.

Both are tested off the phone; neither is run on a phone.

Install#

iOS 17 or later; Android minSdk 24. iOS: in Xcode, File › Add Package Dependencies, enter https://github.com/timbereye23/timbereye-swift, choose the version, and add the product Timbereye to your app target; or in a Package.swift.Android: build the Kotlin SDK from source (sdk/kotlin).

Swift
dependencies: [.package(url: "https://github.com/timbereye23/timbereye-swift", from: "0.1.0")],
targets: [.target(name: "MyApp", dependencies: [.product(name: "Timbereye", package: "timbereye-swift")])]
Kotlin
// Not published yet: build sdk/kotlin from source; the artifact is com.timbereye:timbereye

1. Create a publishable key#

In the console, create a publishable key (te_test_pk_…). It is safe to ship in the app: it can capture into groups, change their spec, add photos and the weight, but cannot read or list your data, and it has daily limits. Options (group_access, spec, allowed app ids): Publishable keys.

2. Configure once, at launch#

Swift
import Timbereye

@main struct MyApp: App {
    init() { Timbereye.configure(publishableKey: "te_test_pk_…") }
    var body: some Scene { WindowGroup { ContentView() } }
}
Kotlin
import com.timbereye.Timbereye

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Timbereye.configure(this, publishableKey = "te_test_pk_…")
    }
}

iOS needs NSCameraUsageDescription in Info.plist (NSLocationWhenInUseUsageDescription is optional: scans record where they were taken). On Android the SDK's manifest brings the camera and location permissions and asks for them with the camera; scanning works without location.

3. Show the scanner#

The group's id is the one your backend kept on its record in step 1.

Swift
TimbereyeScanner(groupId: "grp_7QxV3m") { result in
    dismiss() // the worker left the scanner; the logs are saved and upload by themselves
}
Kotlin
TimbereyeScanner(groupId = "grp_7QxV3m") { result ->
    navController.popBackStack() // the worker left the scanner; the logs are saved and upload by themselves
}

The worker sets species, length and grade, picks how to scan, scans, and goes back when done. Every log is saved on the phone before it is counted and uploads when there is signal; opening the scanner again resumes the same group.

The scanner on a container in the app's demo: its spec (species, length, grade) with Change, and the modes, where the two that measure say the demo does not measure and Count QR tags is chosen; Start scanning.

The scanner as the Timbereye app shows it (the app is built on this same view), in the simulator with demo data. result is the group as the phone sees it:

FieldWhat
idgrp_7QxV3m; nil (null) until a group opened by reference reaches the server
referenceyour record id, ctr_4821
nameMSKU1234567
logseach log: tag, two diameters, species, length, grade, photo; isFinal once refined
logs[].confidencethe log detector's score, 0 to 1, for the box the log was measured in (below)
logs[].photoReferencethe server's image id once the photo is uploaded, and the log's box in it
volumeJAS: m3, logs, logsWithoutLength, finalLogs (device estimates until refined)
saveStatussaved on the phone, waiting for signal, uploading, uploaded, or needs attention

The figures your system keeps do not come back through the app: your backend gets group.measured once the sitting's logs are refined on the server (Stay in sync).

A Done button inside the scanner#

Presented full screen, the scanner has no way out unless you give it one. Ask for its own button:

Swift
var options = ScannerOptions()
options.exitButton = .done // or .cancel; both keep what was scanned
TimbereyeScanner(groupId: "grp_7QxV3m", options: options)
    .onExit { how, result in save(result.logs) } // how: .done, .cancelled, or .left (your app took it away)
Kotlin
Box {
    TimbereyeScanner(groupId = "grp_7QxV3m") { result -> save(result.logs) } // once, when the scanner leaves the screen
    Button(onClick = { navController.popBackStack() }, modifier = Modifier.align(Alignment.TopEnd)) { Text("Done") }
}

On iOS the tap ends the sitting, calls onDone and onExit once, and dismisses the scanner when you presented or pushed it. Without exitButton nothing changes: the worker leaves the way your app placed the scanner. exitButton is iOS only: on Android, put your own button over the scanner, as above. Taking the scanner off the screen ends the sitting and calls onDone once with what was scanned.

Each log's confidence and photo#

log.confidence is the log detector's own score for the box it measured the log in. Use it to rank logs or flag low ones for a person to look at. It is not an accuracy of the diameters and not the chance that the measurement is right, it does not change when the server refines the log, and scores from different detector versions do not compare. Your backend reads the same value as the item's detection_confidence.

log.photoReference names the photo the log was measured on: imageId (img_…) once the photo is uploaded (nil before; read it again after saveStatus is uploaded) and region, the log end's box in that photo (0 to 1 from the top left). Store the reference, not log.photo: the file on the phone is released 7 days after upload. Your backend reads the photo with its secret key, GET /v1/images/{imageId}, and only your organisation can (Read logs, volume and photos).

Phone-first: open a group by your record id#

No backend step: the phone opens the group by your reference and creates it on the server when there is signal. Use your own record id per visit as the reference, and the container number as the name (Reusing a container number).

Swift
TimbereyeScanner(reference: "ctr_4821", kind: .container, name: "MSKU1234567")
Kotlin
TimbereyeScanner(reference = "ctr_4821", kind = GroupKind.Container, name = "MSKU1234567")

Your backend learns of the new group from group.created and links it to ctr_4821 (Stay in sync).

When the worker types a container number#

A container number comes back, so it may already have a group. By default the same reference continues the group last active within 12 hours and starts a new one after that, also offline. To let the worker choose, look the reference up and show the match ("212 logs · last scanned 2 h ago") with Continue this one and Start a new one, the suggestion pre-selected:

Swift
if let match = await Timbereye.lookupGroup(reference: "MSKU1234567", kind: .container) {
    // match.pieces, match.lastScannedAt, match.suggestion (.continue or .new)
}
let group = Timbereye.group(reference: "MSKU1234567", kind: .container, existing: .continue) // .auto, .continue, .new
TimbereyeScanner(group: group)
Kotlin
val match = Timbereye.lookupGroup(reference = "MSKU1234567", kind = GroupKind.Container) // suspend
val group = Timbereye.group(reference = "MSKU1234567", kind = GroupKind.Container, existing = ExistingGroupChoice.Continue)

With signal the lookup asks the server (GET /groups/lookup); offline it uses this phone's own groups for the reference, with the same 12-hour rule. A group opened offline sends when the worker started, so an upload days later decides as it would have then.

Presets and locks#

Fix the mode and the spec for the worker, or leave them free (the default: every mode the phone can run, any spec).

Swift
let options = ScannerOptions(modes: [.qrCount], spec: LogSpec(lengthM: 5.8, species: "PINE_TAEDA"), lockSpec: true)
TimbereyeScanner(groupId: "grp_7QxV3m", options: options)
Kotlin
val options = ScannerOptions(modes = listOf(ScanMode.QrCount), spec = LogSpec(lengthM = 5.8, species = "PINE_TAEDA"), lockSpec = true)
TimbereyeScanner(groupId = "grp_7QxV3m", options = options)

Also: choices (the species, lengths and grades the worker picks from) and units (imperial display; storage stays metric).

UIKit and Android Views#

Swift
let scanner = TimbereyeScannerViewController(groupId: "grp_7QxV3m") { [weak self] result in
    self?.dismiss(animated: true)
}
present(scanner, animated: true)
Kotlin
private val scanner = registerForActivityResult(TimbereyeScannerContract()) { result ->
    // the group when the worker left the scanner (nothing is lost either way)
}

scanner.launch(ScannerRequest(groupId = "grp_7QxV3m"))

The group in your own UI#

Timbereye.group(id:) gives the same group without the scanner: its live logs, JAS volume and upload state.

Swift
@State private var group = Timbereye.group(id: "grp_7QxV3m")

Text("\(group.logs.count) logs · \(group.sync.title)") // redraws as logs are scanned and uploaded
Kotlin
val group = remember { Timbereye.group(id = "grp_7QxV3m") }
group.changes.collectAsState().value // redraws as logs are scanned and uploaded

Text("${group.logs.size} logs · ${group.sync.title}")
SwiftKotlinWhat
logslogsevery log scanned on this phone
volume(.jas)volume(VolumeRule.Jas)JAS: the server's final values where refined, else device estimates
syncsyncwhere the data is: on the phone, uploading, uploaded, needs attention
specspecspecies, length, grade for new logs; setting it updates the group
problemproblemwhat stops scanning or upload, with the worker's message
addPhoto(...)addPhoto(...) (suspend)a photo of the group (seal, ticket, damage), saved and uploaded
setWeight(...)setWeight(...)the weighbridge ticket, saved and uploaded
await retryUploads()retryUploads() (suspend)after the office raised a limit, say
scansscansread-only audit: when, which phone, which mode

Correcting a log the worker has just scanned:

Swift
await group.correct(log.id, spec: LogSpec(lengthM: 6.1)) // or: await group.discard(log.id)
Kotlin
group.correct(log.id, ItemAttributes(lengthMeters = 6.1)) // or: group.discard(log.id)

Capture tokens instead of a publishable key#

For the stricter setup, your server mints a short-lived capture token for each worker, and the SDK asks your app for one when it needs it.

Swift
Timbereye.configure(tokenProvider: { try await myServer.captureToken() })
Kotlin
Timbereye.configure(context, tokenProvider = { myServer.captureToken() })

Modes#

The four capture modes, as the scanner names them:

iOSAndroid
Scale with QR tagYes (qr_scale)Yes (qr_scale)
AR scaleYes (ar_scale), no tag, LiDAR-assisted on iPhone ProNo. Android scales with tags
Count QR tagsYes (qr_count), AR check mark on each logYes (qr_count), no AR
Count from a photoYes (photo_count)Yes (photo_count)

The API calls the mode method. Scale with QR tag and AR scale need the log detector: pass detector: .download (Android: Detector.Download) and the SDK downloads it once from GET /models/detector, checks it and keeps it. Until it is on the phone the scanner shows those modes as off with the reason (downloading, no signal, or none offered by the server), also in Timbereye.availability(of: .qrScale) (Android: Timbereye.availability(ScanMode.QrScale)); Timbereye.retryDetector() tries again. The file (about 16.5 MB on iOS) downloads over any network and is checked against the SHA-256 the server announces before it is kept; a file that does not match is thrown away. Once on the phone it loads at launch before the server is asked, so the measuring modes work with no signal; a newer version replaces it at a later launch. When the server has no model to offer (503 model_unavailable), Timbereye.detector is .notPublished and the scanner says the detector is not available yet. The measuring modes are not run on phones. See What works on the phone. Tags for both tag modes: Print tags; scaling with a tag needs its code printed at 62 mm.

What the SDK sends#

You never write these calls: the scanner makes them with the app's key, adding Timbereye-Installation-Id (a UUID kept per install) and Timbereye-App-Id (the bundle id or package name) to every request. A publishable key gets a capture_group back: the spec and status, never figures, logs or images.

CallWhen
POST /groups/openthe first scan of a group opened by reference
GET /groups/{id}the scanner opens a group by id
PATCH /groups/{id}the worker changed the spec
POST /scans, its items, imageseach sitting at the camera, uploaded when there is signal
POST /images, PUT /groups/{id}/weighta photo or weight the worker added, when there is signal

The libraries underneath (capture engine, offline journal and sync, API client) are there for advanced needs: the README of timbereye-swiftand for Android sdk/kotlin/README.md (the differences in sdk/kotlin/FRONT.md).