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

Get Started


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.

  • Sleep measurement begins analysis when at least 20 minutes of audio is uploaded, after which it is analyzed every 5 minutes or 20 minutes depending on the plan (contract terms).

🔗 Check Test Environment Guideline

1. Requirements

1.1 Minimum requirements on Asleep SDK for iOS


  • Xcode 14.1 or later
  • iOS 14.0 or later
  • Swift 5.0 or later

1.2 API Key

An API key is required to use Asleep SDK.

Regarding how to issue an API key, please refer to Generate API key.

2. Getting Ready

Asleep SDK for iOS is distributed via the native Swift Package Manager built into Xcode.

2.1 Install Asleep SDK

  1. In Xcode, click File > Add Packages.

  2. In the dialog that appears, enter the repository URL

  3. In Version, select Up to Next Major Version and the default option.

  4. Click Add Package button.

  5. Click Add Package button one more time.

  6. In Xcode, click Signing & Capabilities on your application target.

  7. Click + Capability button and double click Background Modes.

  8. Select Audio, AirPlay, and Picture in Picture.

  9. In Xcode, click Info on your app target.

  10. Click + and add Privacy - Microphone Usage Description.

  11. Write a microphone permission request message.

2.2 Import the Asleep SDK

import AsleepSDK

3. Sleep Tracking with Asleep SDK

3.1 Step 1: Initialize the Asleep SDK

  1. Initialize config

    • If userId is nil, a new userId will be generated.
    • Enter the proxy server in baseUrl. If nil, the default base URL will be used.
    • Enter the server to receive the analysis results directly in callbackUrl. If nil, there is no callback.
    • If there is a nickname for the app you are developing, enter it in the service.
    let apiKey: String = "YOUR_API_KEY"
    let userId: String?
    let baseUrl: URL?
    let callbackUrl: URL?
    let service: String?
    let delegate: AsleepConfigDelegate = self  
    Asleep.initAsleepConfig(apiKey: apiKey,
                            userId: userId,
                            baseUrl: baseUrl,
                            callbackUrl: callbackUrl,
                            service: service,
                            delegate: self)
  2. Get config and user ID

    extension YourClass: AsleepConfigDelegate {
        func userDidJoin(userId: String, config: Asleep.Config) {
    	      self.userId = userId
    				self.config = config 
        func didFailUserJoin(error: Asleep.AsleepError) {
        func userDidDelete(userId: String) {
            print("\(userId) is deleted")


Should save userId in your permanent storage for join

3.2 Step 2: Create SleepTrackingManager

var config: Asleep.Config?
let delegate: AsleepSleepTrackingManagerDelegate = self
var manager: Asleep.SleepTrackingManager?

if let config {
    manager = Asleep.createSleepTrackingManager(config: config,
                                                delegate: self)

3.3 Step 3: Start Tracking

var manager: Asleep.SleepTrackingManager?


SDK needs microphone permission for startTracking()

3.4 Step 4: Stop Tracking

var manager: Asleep.SleepTrackingManager?
  1. Get session ID for the sleep report
    extension YourClass: AsleepSleepTrackingManagerDelegate {
        func didClose(sessionId: String) {
          	self.sessionId = sessionId

3.5 Step 5: Create Reports

var config: Asleep.Config?
var reports: Asleep.Reports?

if let config {
    reports = Asleep.createReports(config: config)

3.6 Step 6: Get Report

var reports: Asleep.Reports?
var sessionId: String?

if let reports, let sessionId {
    // Closure sessionId) {
        if let error = $1 {
        if let report = $0 {

    // Async
    Task {
        do {
            let report: Asleep.Model.Report = try await sessionId)	
        } catch {