Skip to content

Commit 1a65fdd

Browse files
Merge pull request #88 from DeveloperAcademy-POSTECH/fix/#85-LiveActivityClean
�fix-#86LiveActivityClean
2 parents 8a50f0f + 95ada57 commit 1a65fdd

File tree

1 file changed

+34
-85
lines changed

1 file changed

+34
-85
lines changed

hearo/hearo/Application/hearoApp.swift

Lines changed: 34 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ final class AppRootManager: ObservableObject {
9898
}
9999

100100
// 라이브 액티비티 시작 메서드
101-
func startLiveActivity(isWarning: Bool) {
102-
// 항상 현재 `Live Activity` 상태를 확인하고 초기화
103-
isActivityActive = Activity<LiveActivityAttributes>.activities.isEmpty == false
101+
func startLiveActivity() {
102+
#if os(iOS) // iOS에서만 라이브 액티비티 실행
103+
// 기존의 Live Activity가 활성화되어 있는지 확인
104+
isActivityActive = !Activity<LiveActivityAttributes>.activities.isEmpty
104105

105106
guard !isActivityActive else {
106107
print("라이브 액티비티가 이미 활성화되어 있습니다.")
@@ -114,9 +115,9 @@ final class AppRootManager: ObservableObject {
114115

115116
// attributes와 initialContentState를 선언
116117
let attributes = LiveActivityAttributes(name: "주행")
117-
let initialContentState = LiveActivityAttributes.ContentState(isWarning: isWarning)
118+
let initialContentState = LiveActivityAttributes.ContentState(isWarning: false)
118119

119-
let content = ActivityContent(state: initialContentState, staleDate: Date().addingTimeInterval(6)) // 전체 6초
120+
let content = ActivityContent(state: initialContentState, staleDate: Date().addingTimeInterval(6))
120121

121122
do {
122123
let activity = try Activity<LiveActivityAttributes>.request(
@@ -125,101 +126,49 @@ final class AppRootManager: ObservableObject {
125126
)
126127

127128
isActivityActive = true
128-
currentWarningState = isWarning
129129
print("라이브 액티비티가 시작되었습니다: \(activity.id)")
130130
} catch {
131131
print("라이브 액티비티 시작 실패: \(error)")
132132
}
133+
#else
134+
print("Apple Watch에서는 라이브 액티비티가 활성화되지 않습니다.")
135+
#endif
133136
}
134-
135-
136-
// 라이브 액티비티 시작 메서드
137-
func startLiveActivity() {
138-
// 기존의 Live Activity가 활성화되어 있는지 확인
139-
isActivityActive = !Activity<LiveActivityAttributes>.activities.isEmpty
140-
141-
guard !isActivityActive else {
142-
print("라이브 액티비티가 이미 활성화되어 있습니다.")
143-
return
144-
}
145-
146-
guard ActivityAuthorizationInfo().areActivitiesEnabled else {
147-
print("라이브 액티비티가 지원되지 않거나 비활성화되었습니다.")
148-
return
149-
}
150-
151-
// attributes와 initialContentState를 선언
152-
let attributes = LiveActivityAttributes(name: "주행")
153-
let initialContentState = LiveActivityAttributes.ContentState(isWarning: false)
154-
155-
let content = ActivityContent(state: initialContentState, staleDate: Date().addingTimeInterval(6))
156-
157-
do {
158-
let activity = try Activity<LiveActivityAttributes>.request(
159-
attributes: attributes,
160-
content: content
161-
)
162-
163-
isActivityActive = true
164-
print("라이브 액티비티가 시작되었습니다: \(activity.id)")
165-
} catch {
166-
print("라이브 액티비티 시작 실패: \(error)")
167-
}
137+
138+
// 라이브 액티비티 종료 메서드
139+
func stopLiveActivity() {
140+
guard !Activity<LiveActivityAttributes>.activities.isEmpty else {
141+
print("라이브 액티비티가 이미 중지 상태입니다.")
142+
return
168143
}
169144

170-
// 라이브 액티비티 종료 메서드
171-
func stopLiveActivity() {
172-
guard !Activity<LiveActivityAttributes>.activities.isEmpty else {
173-
print("라이브 액티비티가 이미 중지 상태입니다.")
174-
return
175-
}
176-
177-
Task {
178-
for activity in Activity<LiveActivityAttributes>.activities {
179-
await activity.end(nil, dismissalPolicy: .immediate)
180-
print("라이브 액티비티가 중지되었습니다: \(activity.id)")
181-
}
182-
isActivityActive = false
183-
print("모든 라이브 액티비티가 성공적으로 중지되었습니다.")
145+
Task {
146+
for activity in Activity<LiveActivityAttributes>.activities {
147+
await activity.end(nil, dismissalPolicy: .immediate)
148+
print("라이브 액티비티가 중지되었습니다: \(activity.id)")
184149
}
150+
isActivityActive = false
151+
print("모든 라이브 액티비티가 성공적으로 중지되었습니다.")
185152
}
186-
187-
188-
// 오디오 및 ML 작업 중지 메서드
189-
func stopAudioAndMLTasks() {
190-
hornSoundDetector?.stopRecording()
191-
print("오디오 수집 및 ML 예측 중지됨")
192-
}
193-
194-
// 오디오 작업을 working 상태에서만 재개하는 메서드
195-
func resumeAudioTasksIfWorking() {
196-
if currentRoot == .working {
197-
hornSoundDetector?.startRecording()
198-
print("오디오 수집 및 ML 예측 재개됨 (working 상태에서만)")
199-
} else {
200-
print("오디오 수집은 working 상태에서만 재개됩니다.")
201-
}
202-
203153
}
154+
204155

205156
// 오디오 및 ML 작업 중지 메서드
206-
func stopAudioAndMLTasks() {
207-
hornSoundDetector?.stopRecording()
208-
print("오디오 수집 및 ML 예측 중지됨")
209-
}
210-
211-
// 오디오 작업을 working 상태에서만 재개하는 메서드
212-
func resumeAudioTasksIfWorking() {
213-
if currentRoot == .working {
214-
hornSoundDetector?.startRecording()
215-
print("오디오 수집 및 ML 예측 재개됨 (working 상태에서만)")
216-
} else {
217-
print("오디오 수집은 working 상태에서만 재개됩니다.")
157+
func stopAudioAndMLTasks() {
158+
hornSoundDetector?.stopRecording()
159+
print("오디오 수집 및 ML 예측 중지됨")
218160
}
219161

162+
// Working 상태에서만 오디오 작업 재개
163+
func resumeAudioTasksIfWorking() {
164+
if currentRoot == .working {
165+
hornSoundDetector?.startRecording()
166+
print("오디오 수집 및 ML 예측 재개됨 (working 상태에서만)")
167+
} else {
168+
print("오디오 수집은 working 상태에서만 재개됩니다.")
169+
}
170+
}
220171
}
221-
222-
}
223172
// ContentView 정의 (AppRootManager 클래스 외부에 위치)
224173
struct ContentView: View {
225174
@ObservedObject var appRootManager: AppRootManager

0 commit comments

Comments
 (0)