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

Get Started

๐Ÿšง

์ˆ˜๋ฉด ์ธก์ • ์‹œ ์•ˆ๋‚ด ์‚ฌํ•ญ์„ ๋”ฐ๋ผ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

Asleep์˜ ์ˆ˜๋ฉด ์ธก์ •/๋ถ„์„ ๊ธฐ๋Šฅ์„ ์ •ํ™•ํ•˜๊ฒŒ ํ…Œ์ŠคํŠธํ•˜๋ ค๋ฉด, โ€จํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ๊ฐ€์ด๋“œ๋ฅผ ๋ฐ˜๋“œ์‹œ ๋”ฐ๋ผ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ์ด ๊ฐ€์ด๋“œ๋ฅผ ์ค€์ˆ˜ํ•˜์ง€ ์•Š์€ ํ™˜๊ฒฝ์—์„œ ์–ป์€ ์ˆ˜๋ฉด ๋ถ„์„ ๊ฒฐ๊ณผ๋Š” โ€จ์‹ค์ œ ์ˆ˜๋ฉด ํŒจํ„ด๊ณผ ์ •ํ™•ํ•˜๊ฒŒ ์ผ์น˜ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ์„ ์œ ์˜ํ•ด์ฃผ์„ธ์š”.

  • ์ˆ˜๋ฉด ์ธก์ •์€ ์ตœ์†Œ 20๋ถ„ ์ด์ƒ์˜ ์˜ค๋””์˜ค๊ฐ€ ์—…๋กœ๋“œ ๋˜์–ด์•ผ ๋ถ„์„์ด ์‹œ์ž‘๋˜๋ฉฐ, ๊ทธ ์ดํ›„๋กœ๋Š” ํ”Œ๋žœ(๊ณ„์•ฝ ์กฐ๊ฑด)์— ๋”ฐ๋ผ 5๋ถ„ ๋˜๋Š” 20๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ”— Test Environment Guideline ํ™•์ธํ•˜๊ธฐ

1. Requirements

1.1 Minimum requirements on Asleep SDK for iOS

๐Ÿšง

  • Xcode 14.1 ํ˜น์€ ๋” ๋†’์€ ๋ฒ„์ „
  • iOS 14.0 ํ˜น์€ ๋” ๋†’์€ ๋ฒ„์ „
  • Swift 5.0 ํ˜น์€ ๋” ๋†’์€ ๋ฒ„์ „

1.2 API Key

์—์ด์Šฌ๋ฆฝ SDK๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” API key๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

API key๋ฅผ ๋ฐœ๊ธ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๋งํฌ Generate API key๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.


2. Getting Ready

์—์ด์Šฌ๋ฆฝ SDK for iOS๋Š” Xcode์— ๋‚ด์žฅ๋œ Swift Package Manager์„ ํ†ตํ•ด ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค.

2.1 Install Asleep SDK

  1. Xcode์—์„œ File > Add Packages๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. ๋‹ค์ด์–ผ๋กœ๊ทธ ์ฐฝ์— repository url์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค https://github.com/asleep-ai/asleep-sdk-ios.

  3. ๋ฒ„์ „์—์„œ, Up to Next Major Version ๋ฐ ๊ธฐ๋ณธ ์˜ต์…˜์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  4. Add Package ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  5. Add Package ๋ฅผ ํ•œ๋ฒˆ ๋” ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  6. Xcode์—์„œ, Targets ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์„ ํƒํ•œ ํ›„ Signing & Capabilities ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  7. + Capability ๋ฅผ ํด๋ฆญํ•˜๊ณ  Background Modes๋ฅผ ๋”๋ธ”ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  8. Audio, AirPlay, and Picture in Picture๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  9. Xcode์—์„œ, ๋ณธ์ธ์˜ Targets ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ Info ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  10. +๋ฅผ ํด๋ฆญํ•˜๊ณ  Privacy - Microphone Usage Description๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  11. ๋งˆ์ดํฌ ๊ถŒํ•œ ์š”์ฒญ ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

2.2 Import the Asleep SDK

import AsleepSDK

3. Sleep Tracking with Asleep SDK

3.1 Step 1: Initialize the Asleep SDK

  1. SDK๋ฅผ ์ดˆ๊ธฐํ™” ํ•ฉ๋‹ˆ๋‹ค

    • userId๊ฐ€ nil์ด๋ฉด ์ƒˆ๋กœ์šด userId๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
    • baseUrl์—๋Š” ํ”„๋ก์‹œ ์„œ๋ฒ„๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. nil์ด๋ฉด default base url์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
    • callbackUrl์€ ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ์ง์ ‘ ๋ฐ›๋Š” ์„œ๋ฒ„๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. nil์ด๋ฉด ์ฝœ๋ฐฑ์ด ์—†์Šต๋‹ˆ๋‹ค.
    • 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. config๊ณผ user ID๋ฅผ ๋ฐ›์•„์˜ต๋‹ˆ๋‹ค

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

โ—๏ธ

join์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ userId๋ฅผ permanent storage ์— ์ €์žฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

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)
}

๐Ÿšง

userDidJoin์—์„œ ๋ฐœ๊ธ‰ ๋ฐ›์€ Asleep.Config์„ ์ด์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

3.3 Step 3: Start Tracking

var manager: Asleep.SleepTrackingManager?
manager?.startTracking()

โ—๏ธ

startTracking()์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด SDK๋Š” ๋งˆ์ดํฌ ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

3.4 Step 4: Stop Tracking

var manager: Asleep.SleepTrackingManager?
manager?.stopTracking()
  1. ์ˆ˜๋ฉด ๋ณด๊ณ ์„œ์˜ session ID๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค
    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)
}

๐Ÿšง

userDidJoin์—์„œ ๋ฐœ๊ธ‰ ๋ฐ›์€ Asleep.Config์„ ์ด์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

3.6 Step 6: Get Report

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

if let reports, let sessionId {
    // Closure
    reports.report(sessionId: sessionId) {
        if let error = $1 {
            print(error)
            return
        }
        
        if let report = $0 {
        }
    }

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