Troubleshooting
Symptoms, causes and fixes for common problems when integrating the iOS SDK.
Find the symptom, check the cause and apply the fix. The capture setup referred to below is the one in the Quickstart.
Setup
The app freezes when the measurement screen opens
Cause. NeccessoryMeasurement(keyId:) runs on the main thread. Creating the instance
blocks for a few seconds.
Fix. Create it on a background serial queue and show a loading state until it is
ready. Create it once and reuse it: start() begins each new measurement.
The app crashes when it opens the camera
Cause. Info.plist has no NSCameraUsageDescription.
Fix. Add the key with a short explanation for the user — see Installation.
No frames in the simulator
Cause. The simulator has no camera.
Fix. Run measurements on a physical device.
The initializer throws init_failed
Cause. The SDK could not be created on this device.
Fix. Check that the device meets the requirements. Show an error state instead of the camera. If it keeps happening on a supported device, email support@neccessory.com with the device model and iOS version.
Threading
Main Thread Checker warnings or crashes inside callbacks
Cause. onRealtime, onResult and onError run on the thread that calls
processFrame — your capture queue, not the main thread.
Fix. Dispatch to the main queue before you touch UI:
measurement.onRealtime = { [weak self] update in
DispatchQueue.main.async { self?.show(update) }
}Intermittent crashes around start() or stop()
Cause. Methods are called from different threads — for example, start() from the
main thread while frames arrive on the capture queue. NeccessoryMeasurement is not
thread-safe.
Fix. Make every call on one serial queue, the one that receives camera frames:
captureQueue.async { measurement.start() }Frames
onRealtime never fires
Cause. processFrame is not called. Typical reasons: camera access was denied, the
capture session is not running, the sample buffer delegate is not set, or frames arrive
before the instance exists.
Fix. Check AVCaptureDevice.authorizationStatus(for: .video), confirm that
captureOutput(_:didOutput:from:) is called, and start the camera only after the instance
is created.
hint stays noFace with a face in view
Cause. The frames are not kCVPixelFormatType_32BGRA, or they arrive rotated.
Fix. Request 32BGRA from the video output and set portrait orientation on its connection:
output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA]
output.connection(with: .video)?.videoOrientation = .portraithint is lowSampleRate
Cause. Frames reach the SDK too slowly. The camera runs below 30 fps, or heavy work on the capture queue — including work inside SDK callbacks — makes the camera drop frames.
Fix.
- Lock the camera at 30 fps by setting both
activeVideoMinFrameDurationandactiveVideoMaxFrameDurationtoCMTime(value: 1, timescale: 30). - Keep other image processing off the capture queue.
- In callbacks, dispatch to the main queue and return.
Metrics are implausible although the camera runs at 30 fps
Cause. timestampSeconds is in milliseconds, comes from the wall clock, or does not
always increase. The SDK derives all timing from your timestamps.
Fix. Pass the frame's presentation time in seconds:
let timestamp = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer))
measurement.processFrame(pixelBuffer: pixelBuffer, timestampSeconds: timestamp)Signal quality
hint is tooDark
Cause. Not enough light reaches the face.
Fix. Ask the user to face a window or a lamp, with even light from the front and no bright light behind them.
hint is unstable
Cause. The face or the phone moves.
Fix. Ask the user to rest the phone on a surface or hold it with both hands, keep their head still and stay silent until the measurement ends.
Every metric in the result is nil
Cause. quality.level is .poor and quality.usable is false: the measurement did
not collect a clean enough signal.
Fix. Coach the user with hint during the measurement and offer to measure again. See
Signal quality and Requirements.
Some metrics are nil, others are present
Cause. HRV, stress and blood pressure need more clean signal than heart rate.
Fix. Hide the missing fields and coach the user to hold still in even light. Keep the
recommended measurement duration: a shorter measurementDurationSeconds lowers accuracy,
HRV most of all.
onResult never fires
Cause. Frames stopped reaching the SDK before the duration elapsed — the app went to
the background, the capture session was interrupted, or processFrame is no longer
called — or stop() was called.
Fix. Keep the camera running until onResult fires, and watch remainingSeconds. After
an interruption, call start() to begin a new measurement.
Submitting results
submit(_:) throws no_secret
Cause. The instance was created without secret.
Fix. Send the result to your backend and store it from there — see
Quickstart. To submit from the device, pass secret to the
initializer.
submit(_:) throws "401"
Cause. The server rejected the signature. The key ID or secret is wrong, the key is disabled or expired, or the device clock is off by more than 5 minutes.
Fix. Check the key in the console and turn on automatic date and time on the device. The exact reason is recorded in your key's usage log.
submit(_:) throws submit_failed or URLError
Cause. The request did not reach the server, usually because the device is offline.
Fix. Keep the result on the device and retry when the connection returns.