# iOS

### **이 글에서는**

**SpaceSDK-iOS**는 FREEGROW Inc.에서 개발한 UWB 기반 iOS SDK입니다.\
iOS 디바이스와 GrowSpace UWB 장비 간 BLE + UWB 통신을 통해 거리 측정 및 실내 위치 추정을 간편하게 구현할 수 있습니다.

***

### 주요 기능

* BLE + UWB 거리 측정 (Ranging)
* RTLS 기반 2D/3D 위치 추정 (x, y, z)
* 실시간 디바이스 연결/해제 콜백 제공
* 한 줄 코드로 시작할 수 있는 간편한 API

***

### 설치 방법 (SPM)

**Swift Package Manager**를 통해 아래 링크를 추가해주세요:

```
https://github.com/freegrowenterprise/SpaceSDK-iOS
```

* Xcode → File → Add Packages
* 위 URL을 입력하고 최신 버전 선택

***

### 권한 설정 (Info.plist)

```xml
<key>NSBluetoothAlwaysUsageDescription</key>
<string>BLE 장치 검색 및 연결을 위해 필요합니다.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>BLE 및 UWB 위치 추정을 위해 필요합니다.</string>
<key>NSNearbyInteractionUsageDescription</key>
<string>UWB 거리 측정을 위해 필요합니다.</string>
<key>NSMotionUsageDescription</key>
<string>정확한 위치 추정을 위해 모션 데이터가 필요합니다.</string>
```

***

### SDK 초기화

```swift
let spaceSDK = GrowSpaceSDK()
```

***

### 거리 측정 시작

```swift
spaceSDK.startUWBRanging(
    maximumConnectionCount: 3,
    onUpdate: { result in
        print("장치: \(result.deviceName), 거리: \(result.distance)m")
    },
    onDisconnect: { result in
        print("연결 해제: \(result.deviceName)")
    }
)
```

***

### 거리 측정 중지

```swift
spaceSDK.stopUWBRanging {
    print("✅ 거리 측정 중지 완료")
}
```

***

### RTLS 위치 추정

```swift
let anchors = [
    "FGU-0001": (x: 0.0, y: 0.0, z: 0.0),
    "FGU-0002": (x: 5.0, y: 0.0, z: 0.0),
    "FGU-0003": (x: 0.0, y: 5.0, z: 0.0)
]

spaceSDK.startUwbRTLS(
    anchorPositions: anchors,
    onResult: { location in
        print("현재 위치: x=\(location.x), y=\(location.y), z=\(location.z)")
    },
    onFail: { reason in
        print("위치 추정 실패: \(reason)")
    }
)
```

***

#### 배터리 정보 (추가 예정) <a href="#undefined-7" id="undefined-7"></a>

```swift
spaceSDK.battery (
    onResult: { battery in
        print("배터리: \(battery)")
    },
    onFail: { reason in
        print("배터리 정보 추정 실패: \(reason)")
    }
)
```

***

### 테스트 앱

SpaceSDK-iOS의 모든 기능은 아래 공식 테스트 앱에서 직접 체험하실 수 있습니다:

* [GitHub 테스트 앱 코드](https://github.com/freegrowenterprise/SpaceSDK-iOS-TestApp)
* [App Store](https://apps.apple.com/us/app/space-uwb/id6745208882)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://freegrow-1.gitbook.io/product-docs-kr/ko-mobile-kit-n1/uwb-n1-sdk/sdk/ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
