NeccessoryNeccessory
iOS SDK

Results

Live updates, hints, the final measurement result and error codes of the iOS SDK, as Swift types.

The SDK reports progress through onRealtime and delivers the final result through onResult. Both carry plain Swift values: RealtimeUpdate and MeasurementResult.

Live updates

onRealtime fires repeatedly while frames arrive: before start() for the pre-check, and during the measurement.

FieldTypeDescription
heartRateInt?Live heart rate, bpm. nil until the reading is stable
qualityLevelQualityLevelCurrent signal quality: .good, .fair or .poor
qualityScoreDoubleCurrent signal quality, 0–1
elapsedSecondsDoubleSeconds measured so far
remainingSecondsDoubleSeconds left. Drive a countdown or a progress ring with it
hintString?What the user should fix right now. nil when the frames are usable

Present the live heart rate as provisional. The final value is in the result.

Hints

Turn hint into a short instruction on screen. Before start(), enable your Start button once hint is nil.

hintMeaningMessage (English)Message (Russian)
noFaceNo face in the frameLook at the cameraСмотрите в камеру
faceTooSmallThe face is too far awayMove closerПридвиньтесь ближе
faceTooLargeThe face is too closeMove back a littleОтодвиньтесь немного
tooDarkNot enough light on the faceFind more lightНужно больше света
unstableThe face or the camera is movingHold stillНе двигайтесь
lowSampleRateFrames arrive too slowlyCamera frame rate is too lowНизкая частота кадров камеры
lowSnrThe pulse signal is weakHold still and keep the light evenНе двигайтесь, свет должен быть ровным
insufficientMetricsThe measurement needs more clean signalKeep goingПродолжаем замер
modelErrorThe SDK could not process the framesSomething went wrong. Try againЧто-то пошло не так. Попробуйте ещё раз

lowSampleRate points to your capture setup rather than to the user — see Troubleshooting. After modelError, call start() to begin a new measurement.

The result

onResult fires once per measurement with a MeasurementResult. It follows the measurement result shared by every platform. An iOS result contains the core metrics — heart rate, HRV with time-domain and Poincaré indices, breathing rate and stress — plus beta estimates of blood pressure and SpO2.

Summary and quality

PropertyTypeDescription
sourceStringAlways "ios"
durationSecDoubleMeasurement length, seconds
isCompleteBoolWhether the measurement ran its full duration
quality.levelQualityLevel.good, .fair or .poor
quality.scoreDoubleSignal quality, 0–1
quality.usableBoolfalse when level is .poor

Core metrics

PropertyTypeDescription
cardiac.heartRate.valueInt?Heart rate, bpm
cardiac.heartRate.confidenceDouble?Confidence in the heart rate, 0–1
hrv.sdnnMsInt?HRV: SDNN, ms
hrv.rmssdMsInt?RMSSD, ms
hrv.pnn50PctDouble?pNN50, %
hrv.sd1Ms, hrv.sd2MsDouble?Poincaré SD1 and SD2, ms
hrv.sd1Sd2RatioDouble?SD1 / SD2
hrv.csi, hrv.cviDouble?Cardiac sympathetic and cardiac vagal indices
respiratory.breathingRate.valueInt?Breathing rate, breaths per minute
stress.indexInt?Stress index, 0–100
stress.levelStressLevel?.low, .moderate or .high

Beta metrics

PropertyTypeDescription
bloodPressure.systolicMmHgInt?Blood pressure: systolic, mmHg
bloodPressure.diastolicMmHgInt?Diastolic, mmHg
bloodPressure.mapMmHgInt?Mean arterial pressure, mmHg
bloodPressure.ppMmHgInt?Pulse pressure, mmHg
spo2.valueInt?SpO2, %
bloodPressure.tier, spo2.tierStringAlways "beta"
bloodPressure.disclaimer, spo2.disclaimerStringText to show next to the values

Every metric section also has a unit string: "bpm", "brpm", "index", "mmHg" or "%".

Show the result

func rows(for result: MeasurementResult) -> [(label: String, value: String)] {
    guard result.quality.usable else { return [] }

    var rows: [(label: String, value: String)] = []
    if let bpm = result.cardiac.heartRate.value {
        rows.append((label: "Heart rate", value: "\(bpm) bpm"))
    }
    if let sdnn = result.hrv.sdnnMs {
        rows.append((label: "HRV", value: "\(sdnn) ms"))
    }
    if let breaths = result.respiratory.breathingRate.value {
        rows.append((label: "Breathing rate", value: "\(breaths) /min"))
    }
    if let stress = result.stress.level {
        rows.append((label: "Stress", value: stress.rawValue))
    }
    if let systolic = result.bloodPressure.systolicMmHg, let diastolic = result.bloodPressure.diastolicMmHg {
        rows.append((label: "Blood pressure (beta)", value: "\(systolic)/\(diastolic) mmHg"))
    }
    if let spo2 = result.spo2.value {
        rows.append((label: "SpO2 (beta)", value: "\(spo2) %"))
    }
    return rows
}
  • Check quality.usable first. When it is false, every metric value is nil. Ask the user to measure again, holding still in even light. .fair results are usable — see Signal quality.
  • Handle nil for each metric. Even with good quality, a single metric can be nil when it did not collect enough clean signal; HRV and blood pressure need more than heart rate. Hide the field instead of showing 0 or a placeholder.
  • Keep beta values visually secondary. Show blood pressure and SpO2 below the core metrics, with their disclaimer.

Wellness use only

Blood pressure and SpO2 are beta estimates for wellness use. They are not a medical device. Show the disclaimer text next to them — see Disclaimer.

Store the result

MeasurementResult is Codable, and JSONEncoder turns it into a valid body for POST /sdk/v1/measurements: the keys match the API, and nil values are omitted.

let body = try JSONEncoder().encode(result)
{
  "source": "ios",
  "durationSec": 30.1,
  "isComplete": true,
  "quality": { "level": "good", "score": 0.82, "usable": true },
  "cardiac": { "heartRate": { "value": 72, "unit": "bpm", "confidence": 0.88 } },
  "hrv": {
    "sdnnMs": 48, "rmssdMs": 41, "pnn50Pct": 12.5,
    "sd1Ms": 29.1, "sd2Ms": 61.4, "sd1Sd2Ratio": 0.47, "csi": 2.11, "cvi": 3.25
  },
  "respiratory": { "breathingRate": { "value": 15, "unit": "brpm" } },
  "stress": { "index": 34, "level": "moderate", "unit": "index" },
  "bloodPressure": {
    "systolicMmHg": 118, "diastolicMmHg": 77, "mapMmHg": 91, "ppMmHg": 41,
    "unit": "mmHg", "tier": "beta",
    "disclaimer": "Estimate for wellness use only. Not a medical device."
  },
  "spo2": {
    "value": 97, "unit": "%", "tier": "beta",
    "disclaimer": "Estimate for wellness use only. Not a medical device."
  }
}

Send this JSON to your backend, add userRef there and store it with a signed request — see Quickstart. The stored measurement gets an id (meas_…) and carries origin: "on_device" and attested: false, because the device computed it — see Attested results. Storing results is free. With a test key (nk_test_…), stored results are marked test: true.

Errors

MeasurementError has a code and a readable message. Problems with frames never raise an error: they arrive as hint.

CodeWhereMeaningWhat to do
init_failedThrown by the initializerThe SDK could not be createdShow an error state instead of the camera. If it repeats on a device, contact support@neccessory.com with the device model and iOS version
start_failedonErrorThe measurement could not startLet the user try again with start()
no_secretThrown by submit(_:)The instance was created without secretStore the result through your backend, or pass secret to the initializer
submit_failedThrown by submit(_:)No HTTP response from the serverKeep the result and retry later
"400", "401", "429", …Thrown by submit(_:)The server rejected the request; the code is the HTTP status. message carries the server's error messageSee Errors. For "401", see Troubleshooting

submit(_:) can also throw URLError, for example without a network connection, and EncodingError.