SleepTrackingManager
1. Create manager
Asleep.createSleepTrackingManager()
var config: Asleep.Config?
let delegate: AsleepSleepTrackingManagerDelegate = self
var manager: Asleep.SleepTrackingManager?
if let config {
manager = Asleep.createSleepTrackingManager(config: config,
delegate: delegate)
}
Property Name | Type | Description |
---|---|---|
config | Asleep.Config | Enter the Asleep.Config instance |
delegate | AsleepConfigDelegate | Delegate to receive results and errors |
AsleepSleepTrackingManagerDelegate
protocol AsleepSleepTrackingManagerDelegate {
func didCreate()
func didUpload(sequence: Int)
func didClose(sessionId: String)
func didFail(error: Asleep.AsleepError)
func didInterrupt()
func didResume()
func micPermissionWasDenied()
func analysing(session: Asleep.Model.Session)
}
-
didCreate()
Tracking is generated. -
didUpload()
Data is uploaded.Property Name Type Description sequence Int A value that starts from 0 and increases by 1 every 30 seconds -
didClose()
Tracking is terminated.Property Name Type Description sessionId String Report result id value -
didFail()
Due to error, tracking is endedProperty Name Type Description error Asleep.AsleepError Error Codes -
didInterrupt()
Tracking is interrupted due to events such as calls. -
didResume()
Tracking resumes once the interrupting factor is resolved. -
micPermissionWasDenied()
Tracking cannot be started without microphone permission. -
analysing()
Latest session dataProperty Name Type Description session Asleep.Model.Session during analysis, tracking session information
2. Start sleep tracking
Asleep.SleepTrackingManager.startTracking()
var manager: Asleep.SleepTrackingManager?
manager?.startTracking()
Follow the guideline for testing the sleep tracking
To accurately test Asleep's sleep tracking/analysis, please follow the test environment guide. Please note that sleep analysis results obtained in environments not adhering to this guide may not accurately reflect actual sleep patterns.
🔗 Check Test Environment Guideline
3. Request the latest analyzed session
Asleep.SleepTrackingManager.requestAnalysis()
var manager: Asleep.SleepTrackingManager?
manager?.requestAnalysis()
4. Stop sleep tracking
Asleep.SleepTrackingManager.stopTracking()
var manager: Asleep.SleepTrackingManager?
manager?.stopTracking()
5. Data Type
Asleep.Model.Session
struct Session {
let id: String
let state: State
let startTime: Date
let endTime: Date?
let sleepStages: [SleepStage]
let osaStages: [OSAStage]
}
enum State {
case open
case closed
case complete
}
enum SleepStage {
case error
case wake
case light
case deep
case rem
}
enum OSAStage {
case stable
case unstable
}
Property name | Type | Description |
---|---|---|
id | String | Sleep session id |
state | Asleep.Model.State | Sleep session state (OPEN , CLOSED , or COMPLETE ) |
startTime | Date | Session start time |
endTime | Date? | Session end datre |
sleepStages | Array<Asleep.Model.SleepStage> | Sleep stages |
osaStages | Array<Asleep.Model.OSAStage> | Sleep apnea stages |
Updated over 1 year ago