1. Create manager


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


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


var manager: Asleep.SleepTrackingManager?


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


var manager: Asleep.SleepTrackingManager?

4. Stop sleep tracking


var manager: Asleep.SleepTrackingManager?

5. Get sleep tracking status


  • Available from v2.1.2
var manager: Asleep.SleepTrackingManager?
let trackingStatus = manager?.getTrackingStatus()

6. Resume tracking


  • If a cannotActivateInBackground error occurs during sleep tracking, notify the user (e.g., through a notification), and run Asleep.SleepTrackingManager.resumeTracking() while the app is in the foreground.
  • v2.4.5 <= SDK
var manager: Asleep.SleepTrackingManager?

7. Data Type


  • Available from v2.1.2
Property nameTypeDescription
sessionIdString?Currently tracking session id
Available from the didCreate function of AsleepSleepTrackingManagerDelegate
Valid until the corresponding Session is closed


struct Session {
    let id: String
    let state: State
    let startTime: Date
    let endTime: Date?
    let unexpectedEndTime: Date?
    let createdTimezone: String
    let sleepStages: [Int]?
    let breathStages: [Int]?

enum State {
    case open
    case closed
    case complete
Property nameTypeDescriptionVersion
idStringSleep session id
stateAsleep.Model.StateSleep session state (OPEN, CLOSED, or COMPLETE)
startTimeDateSession start time
endTimeDate?Session end date
unexpectedEndTimeDate?If a session fails to proceed and terminate properly due to app crashes or similar issues, and the client later executes initConfig to terminate the session, the time at which this happens is recorded. In this case, the "end_time" is calculated based on the sequence number of the last uploaded audio file. Therefore, if "end_time" is not null, it indicates an abnormal session.2.2.0<=SDK
createdTimezoneStringTimezone of session creation (Timezone List)2.2.0<=SDK
sleepStagesArray<Int>Sleep stages
-1: error
0 : wake
1 : light
2 : deep
3 : rem
breathStagesArray<Int>Breathing Stability stages
-1: error
0 : stable
1 : unstable