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. Get sleep tracking status
Asleep.SleepTrackingManager.getTrackingStatus()
- Available from v2.1.2
var manager: Asleep.SleepTrackingManager?
let trackingStatus = manager?.getTrackingStatus()
6. Resume tracking
Asleep.SleepTrackingManager.resumeTracking()
- 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?
manager?.resumeTracking()
7. Data Type
Asleep.SleepTrackingManager.TrackingStatus
- Available from v2.1.2
Property name | Type | Description |
---|---|---|
sessionId | String? | Currently tracking session id Available from the didCreate function of AsleepSleepTrackingManagerDelegate Valid until the corresponding Session is closed |
Asleep.Model.Session
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 name | Type | Description | Version |
---|---|---|---|
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 date | |
unexpectedEndTime | Date? | 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 |
createdTimezone | String | Timezone of session creation (Timezone List) | 2.2.0<=SDK |
sleepStages | Array<Int> | Sleep stages-1 : error0 : wake1 : light2 : deep3 : rem | |
breathStages | Array<Int> | Breathing Stability stages-1 : error0 : stable1 : unstable |
Updated 6 months ago