인터넷 연결 없이 Bluetooth/Wi-Fi를 통해 근처 기기와 채팅할 수 있는 iOS 앱입니다.
- ✅ 오프라인 P2P 채팅
- ✅ Bluetooth 및 Wi-Fi Direct 지원
- ✅ 자동 기기 검색
- ✅ 다중 사용자 동시 연결 (최대 8명)
- ✅ 암호화된 통신 (AES-256)
- ✅ macOS 앱과 크로스 플랫폼 통신
- Xcode → File → New → Project
- iOS → App 선택
- 설정:
- Product Name:
BluetoothChat - Interface:
SwiftUI - Language:
Swift
- Product Name:
BluetoothChat/
├── BluetoothChatApp.swift (기존 파일 교체)
├── ContentView.swift (기존 파일 교체)
├── ChatManager.swift (새로 추가)
└── Message.swift (새로 추가)
TARGETS → BluetoothChat → Info 탭에서 다음 키 추가:
<key>NSLocalNetworkUsageDescription</key>
<string>주변 기기와 채팅하기 위해 로컬 네트워크 접근이 필요합니다.</string>
<key>NSBonjourServices</key>
<array>
<string>_bt-chat-app._tcp</string>
<string>_bt-chat-app._udp</string>
</array>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>주변 기기와 Bluetooth로 통신하기 위해 필요합니다.</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>주변 기기와 Bluetooth로 통신하기 위해 필요합니다.</string>- TARGETS → BluetoothChat → Signing & Capabilities
- Team에 개발자 계정 선택
- Bundle Identifier 설정 (예:
com.yourname.BluetoothChat)
실제 기기 2대 이상 권장 (시뮬레이터는 제한적)
- 두 iPhone에 앱 설치
- 양쪽에서 앱 실행 → 닉네임 입력 → "시작하기"
- 우측 상단 👥 버튼으로 주변 기기 확인
- 발견된 기기 탭하여 연결
- 채팅 시작!
- Bluetooth ON 확인
- Wi-Fi ON 확인 (같은 네트워크 불필요)
- 30m 이내 위치
- "기기 검색" & "내 기기 공개" 활성화
- 앱 삭제 후 재설치
BluetoothChat/
├── BluetoothChatApp.swift # @main 앱 진입점
├── Message.swift # 메시지 데이터 모델
├── ChatManager.swift # @Observable + Multipeer Connectivity
└── ContentView.swift # SwiftUI 뷰
├── SetupView # 닉네임 설정
├── ChatView # 메인 채팅
├── MessageBubble # 말풍선
├── MessageInputView # 입력창
└── PeerListView # 기기 관리
이 버전은 최신 API를 사용합니다:
| 변경 전 | 변경 후 |
|---|---|
@StateObject |
@State (with @Observable) |
@ObservableObject |
@Observable macro |
@Published |
일반 프로퍼티 |
onChange(of:) { newValue in } |
onChange(of:) { } |
.foregroundColor() |
.foregroundStyle() |
.cornerRadius() |
.clipShape(RoundedRectangle()) |
- iOS 17.0 이상
- Xcode 26.0 이상
- Swift 6.0 이상
동일한 serviceType: "bt-chat-app"을 사용하므로 macOS 앱과 자동으로 연결됩니다!
Made with ❤️ using SwiftUI & Multipeer Connectivity