These docs are for v1.0. Click to read the latest docs for v2.0.

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 NameTypeDescription
configAsleep.ConfigEnter the Asleep.Config instance
delegateAsleepConfigDelegateDelegate 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)
}
  1. didCreate()
    Tracking is generated.

  2. didUpload()
    Data is uploaded.

    Property NameTypeDescription
    sequenceIntA value that starts from 0 and increases by 1 every 30 seconds
  3. didClose()
    Tracking is terminated.

    Property NameTypeDescription
    sessionIdStringReport result id value
  4. didFail()
    Due to error, tracking is ended

    Property NameTypeDescription
    errorAsleep.AsleepErrorError Codes
  5. didInterrupt()
    Tracking is interrupted due to events such as calls.

  6. didResume()
    Tracking resumes once the interrupting factor is resolved.

  7. micPermissionWasDenied()
    Tracking cannot be started without microphone permission.

  8. analysing()
    Latest session data

    Property NameTypeDescription
    sessionAsleep.Model.Sessionduring 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 nameTypeDescription
idStringSleep session id
stateAsleep.Model.StateSleep session state (OPEN, CLOSED, or COMPLETE)
startTimeDateSession start time
endTimeDate?Session end datre
sleepStagesArray<Asleep.Model.SleepStage>Sleep stages
osaStagesArray<Asleep.Model.OSAStage>Sleep apnea stages