Conversation
- 임시 버전, todo로 남은 부분 명세
WalkthroughIntroduces a BluetoothManager to handle BLE scanning/connection and a courtesy-seat notification flow. HomeView integrates this manager, adds confirmation/success/failure alerts, and triggers notifications when a route is selected. Info.plist adds Bluetooth permission usage descriptions required for scanning and peripheral access. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant HomeView
participant BluetoothManager
participant CBCentralManager as CoreBluetooth
User->>HomeView: Tap "Send courtesy seat" (route selected)
HomeView->>HomeView: Show confirm alert
User-->>HomeView: Confirm
HomeView->>BluetoothManager: sendCourtesySeatNotification(busNumber)
BluetoothManager->>CBCentralManager: startScan()
Note over BluetoothManager,CBCentralManager: Timeout set (10s)
CBCentralManager-->>BluetoothManager: didDiscover(peripheral)
BluetoothManager->>CBCentralManager: connect(peripheral)
CBCentralManager-->>BluetoothManager: didConnect(peripheral)
Note over BluetoothManager: Placeholder: discover services/characteristics<br/>and write "courtesy seat" signal
BluetoothManager->>CBCentralManager: stopScan()/disconnect()
alt Success
BluetoothManager-->>HomeView: completion(true)
HomeView->>HomeView: Show success alert
else Failure/Timeout
BluetoothManager-->>HomeView: completion(false)
HomeView->>HomeView: Show failure alert
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
ComfortableMove/ComfortableMove/Core/Home/HomeView.swift(3 hunks)ComfortableMove/ComfortableMove/Core/Manager/BluetoothManager.swift(1 hunks)ComfortableMove/ComfortableMove/Info.plist(1 hunks)
🧰 Additional context used
🪛 SwiftLint (0.57.0)
ComfortableMove/ComfortableMove/Core/Manager/BluetoothManager.swift
[Warning] 78-78: TODOs should be resolved (버스 기기만 필터링하는 로직 추가 필요)
(todo)
[Warning] 83-83: TODOs should be resolved (임시 코드 - 첫 번째 발견된 기기에 무조건 연결 시도)
(todo)
[Warning] 95-95: TODOs should be resolved (실제 배려석 알림 신호 전송 로직 구현 필요)
(todo)
[Warning] 103-103: TODOs should be resolved (임시 코드 - 연결만 성공해도 전송 성공으로 간주)
(todo)
| DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in | ||
| guard let self = self else { return } | ||
| if self.isScanning { | ||
| self.stopScanning() | ||
| self.onTransmitComplete?(false) | ||
| } |
There was a problem hiding this comment.
Reset connection state on failures/timeouts.
When the timeout fires or didFailToConnect runs, targetPeripheral stays non-nil. A subsequent scan won’t connect to anything because the guard in didDiscover keeps the stale peripheral, and onTransmitComplete can be invoked multiple times across retries. Clear the peripheral reference (and the completion) whenever we abandon a transmission.
DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
guard let self = self else { return }
if self.isScanning {
self.stopScanning()
+ self.targetPeripheral = nil
self.onTransmitComplete?(false)
+ self.onTransmitComplete = nil
}
}
@@
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
print("기기 연결 실패: \(error?.localizedDescription ?? "알 수 없는 오류")")
stopScanning()
+ targetPeripheral = nil
onTransmitComplete?(false)
+ onTransmitComplete = nil
}Also applies to: 111-115
🤖 Prompt for AI Agents
In ComfortableMove/ComfortableMove/Core/Manager/BluetoothManager.swift around
lines 39-44 (and also apply same change to lines ~111-115), the
timeout/failed-connect paths abandon a transmission but leave targetPeripheral
and onTransmitComplete set, causing stale peripheral guards and duplicate
completion calls; update the timeout closure and didFailToConnect handler to
reset state by setting targetPeripheral = nil and capturing & clearing
onTransmitComplete (call it once then set to nil) before invoking it, and ensure
stopScanning()/disconnect logic still runs so subsequent scans can pick new
peripherals and retries won't double-invoke the completion.
| // TODO: 임시 코드 - 첫 번째 발견된 기기에 무조건 연결 시도 | ||
| // 실제로는 버스 기기인지 확인 후 연결해야 함 | ||
| if targetPeripheral == nil { | ||
| targetPeripheral = peripheral | ||
| centralManager.connect(peripheral, options: nil) | ||
| } |
There was a problem hiding this comment.
Stop scanning before initiating a connection attempt.
isScanning stays true until stopScanning() runs, so the 10 s timeout closure still sees the scan as active while centralManager.connect is in-flight. The timeout then fires, forces a failure callback, and a later didConnect/didFailToConnect triggers a second callback, leaving the UI in an inconsistent state. Stop the scan as soon as you select a target peripheral so the timeout can no longer trip the failure path.
if targetPeripheral == nil {
targetPeripheral = peripheral
- centralManager.connect(peripheral, options: nil)
+ stopScanning()
+ centralManager.connect(peripheral, options: nil)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // TODO: 임시 코드 - 첫 번째 발견된 기기에 무조건 연결 시도 | |
| // 실제로는 버스 기기인지 확인 후 연결해야 함 | |
| if targetPeripheral == nil { | |
| targetPeripheral = peripheral | |
| centralManager.connect(peripheral, options: nil) | |
| } | |
| // TODO: 임시 코드 - 첫 번째 발견된 기기에 무조건 연결 시도 | |
| // 실제로는 버스 기기인지 확인 후 연결해야 함 | |
| if targetPeripheral == nil { | |
| targetPeripheral = peripheral | |
| stopScanning() | |
| centralManager.connect(peripheral, options: nil) | |
| } |
🧰 Tools
🪛 SwiftLint (0.57.0)
[Warning] 83-83: TODOs should be resolved (임시 코드 - 첫 번째 발견된 기기에 무조건 연결 시도)
(todo)
🤖 Prompt for AI Agents
In ComfortableMove/ComfortableMove/Core/Manager/BluetoothManager.swift around
lines 83–88, stop the scanner immediately before calling centralManager.connect
to prevent the existing scan timeout from still being active and triggering a
spurious failure; call centralManager.stopScan() (and update any isScanning
state) right after selecting targetPeripheral and, if you have a scan timeout
timer/closure, invalidate or cancel it before initiating connect so only the
real connect callbacks (didConnect/didFailToConnect) drive UI state.
개요
스크린샷
수정사항
TODO
아직까지 ESP32 모듈 세팅에 관해 수행되지 않았기 때문에 블루투스 기능 테스트를 위한 코드 작성을 했습니다.
해당 부분들은 ESP32 모듈 설정 이후 개선할 예정입니다.
Summary by CodeRabbit
New Features
Chores