Skip to content

Commit

Permalink
Merge pull request #40 from DeveloperAcademy-POSTECH/Fix/#32-LiveActi…
Browse files Browse the repository at this point in the history
…vityButton

Fix/#32-LiveActivityButton
  • Loading branch information
KimPilGyeom authored Nov 6, 2024
2 parents 7e6a094 + bc70d30 commit 51b235f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 167 deletions.
34 changes: 0 additions & 34 deletions hearo/LiveActivity/AppIntent.swift

This file was deleted.

65 changes: 0 additions & 65 deletions hearo/LiveActivity/LiveActivity.swift

This file was deleted.

4 changes: 1 addition & 3 deletions hearo/LiveActivity/LiveActivityBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import SwiftUI
@main
struct LiveActivityBundle: WidgetBundle {
var body: some Widget {
// 라이브 액티비티 위젯 추가
LiveActivity()
LiveActivityLiveActivity() // 다이내믹 아일랜드와 연결된 라이브 액티비티 추가
LiveActivityLiveActivity() // 다이내믹 아일랜드와 연결된 라이브 액티비티만 추가
}
}
49 changes: 15 additions & 34 deletions hearo/LiveActivity/LiveActivityLiveActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,55 @@ import SwiftUI
// 라이브 액티비티 속성 정의
struct LiveActivityAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
var isWarning: Bool // 경고 상태를 나타냄
// 현재 상태를 나타내는 속성을 정의 (예: 경고 여부)
// 하지만 필요 없다면 이 속성을 추가적으로 활용할 수 있습니다.
}
var name: String
}

var name: String // 이름 속성만 유지
}
struct LiveActivityLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: LiveActivityAttributes.self) { context in

// UI 구성
HStack {
// UI
VStack {
Text("안전주행중")
Text("소리 수집이 중지되었습니다.") // 변경된 메시지
.font(.headline)
.foregroundColor(.white)
Button(action: {
stopWorking()
}) {
Label("정지", systemImage: "stop.fill")
.foregroundColor(.red)
}
}

Spacer()


Image(systemName: "car.fill") // 캐릭터로 대체 예정
Image(systemName: "exclamationmark.triangle") // 경고 아이콘
.resizable()
.scaledToFit()
.frame(width: 40, height: 40)
.foregroundColor(.white)
}
.padding()
.containerBackground(for: .widget) {
// 배경 설정: 검정색으로 설정
Color.black
Color.black // 배경 색상
}
.activityBackgroundTint(Color.black)
.activitySystemActionForegroundColor(Color.white)

.activitySystemActionForegroundColor(Color.white)
} dynamicIsland: { context in
DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Image(systemName: context.state.isWarning ? "exclamationmark.triangle" : "figure.walk")
Image(systemName: "exclamationmark.triangle")
}
DynamicIslandExpandedRegion(.center) {
Text(context.state.isWarning ? "경고 상태" : "주행중")
Text("소리 수집이 중지되었습니다.") // 동일한 메시지
}
DynamicIslandExpandedRegion(.trailing) {
Button(action: {
stopWorking()
}) {
Image(systemName: "stop.fill")
}
// 추가 아이콘이나 요소가 필요하다면 여기에 추가
}
} compactLeading: {
Image(systemName: context.state.isWarning ? "exclamationmark.triangle" : "figure.walk")
Image(systemName: "exclamationmark.triangle")
} compactTrailing: {
Text("주행중")
Text("수집 중지")
} minimal: {
Image(systemName: context.state.isWarning ? "exclamationmark.triangle" : "figure.walk")
Image(systemName: "exclamationmark.triangle")
}
}
}
}

// 정지 함수 예시
func stopWorking() {
// WorkingViewModel의 주행 종료 기능과 연동해야 합니다.
NotificationCenter.default.post(name: NSNotification.Name("StopWorkingNotification"), object: nil)
}
60 changes: 31 additions & 29 deletions hearo/hearo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@
007BEFCE2CB159AD00C0E9FD /* WorkingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 007BEFCD2CB159AD00C0E9FD /* WorkingView.swift */; };
007BEFD02CB159BF00C0E9FD /* WorkingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 007BEFCF2CB159BF00C0E9FD /* WorkingViewModel.swift */; };
00A04EA72CB7CBB20031DECC /* SpoqaHanSansNeo_OTF_original in Resources */ = {isa = PBXBuildFile; fileRef = 00A04EA62CB7CBB20031DECC /* SpoqaHanSansNeo_OTF_original */; };
00FC15162CDA10B700FBCE0C /* HornSoundClassifier_V9.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 00FC15152CDA10B700FBCE0C /* HornSoundClassifier_V9.mlmodel */; };

112177742CC283BC000A146F /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 112177732CC283BC000A146F /* WidgetKit.framework */; };
112177762CC283BC000A146F /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 112177752CC283BC000A146F /* SwiftUI.framework */; };
112177792CC283BC000A146F /* LiveActivityBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112177782CC283BC000A146F /* LiveActivityBundle.swift */; };
1121777B2CC283BC000A146F /* LiveActivityLiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1121777A2CC283BC000A146F /* LiveActivityLiveActivity.swift */; };
1121777D2CC283BC000A146F /* LiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1121777C2CC283BC000A146F /* LiveActivity.swift */; };
1121777F2CC283BC000A146F /* AppIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1121777E2CC283BC000A146F /* AppIntent.swift */; };
112177812CC283BD000A146F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 112177802CC283BD000A146F /* Assets.xcassets */; };
112177852CC283BD000A146F /* LiveActivityExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 112177712CC283BC000A146F /* LiveActivityExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
645C1B162CCBB3BF00251157 /* OnboardingWelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 645C1B152CCBB3BF00251157 /* OnboardingWelcomeView.swift */; };
645C1B182CCBB53C00251157 /* OnboardingNotiPermissionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 645C1B172CCBB53C00251157 /* OnboardingNotiPermissionView.swift */; };
645C1B1A2CCBBB4800251157 /* OnboardingPrivacyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 645C1B192CCBBB4800251157 /* OnboardingPrivacyView.swift */; };
645C1B1C2CCBBE7000251157 /* OnboardingWarningView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 645C1B1B2CCBBE7000251157 /* OnboardingWarningView.swift */; };
645C1B1E2CCBBFAB00251157 /* OnboardingStandRecommendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 645C1B1D2CCBBFAB00251157 /* OnboardingStandRecommendView.swift */; };

1159334C2CDB2A7C005902F2 /* HornSoundClassifier_V11.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 1159334B2CDB2A7C005902F2 /* HornSoundClassifier_V11.mlmodel */; };

64F73A252CBAC9F100D2A140 /* HornSoundDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64F73A242CBAC9F100D2A140 /* HornSoundDetector.swift */; };
64F73A272CBAD1C000D2A140 /* SoundDetectorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64F73A262CBAD1C000D2A140 /* SoundDetectorViewModel.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -153,22 +149,17 @@
007BEFCF2CB159BF00C0E9FD /* WorkingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkingViewModel.swift; sourceTree = "<group>"; };
00A04EA62CB7CBB20031DECC /* SpoqaHanSansNeo_OTF_original */ = {isa = PBXFileReference; lastKnownFileType = folder; path = SpoqaHanSansNeo_OTF_original; sourceTree = "<group>"; };
00A04EA82CB7CC320031DECC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
00AD926C2CD227A200DDA11B /* HearoadWatch.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HearoadWatch.entitlements; sourceTree = "<group>"; };
00FC15152CDA10B700FBCE0C /* HornSoundClassifier_V9.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; name = HornSoundClassifier_V9.mlmodel; path = ../../../../../../../Downloads/HornSoundClassifier_V9.mlmodel; sourceTree = "<group>"; };

112177712CC283BC000A146F /* LiveActivityExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = LiveActivityExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
112177732CC283BC000A146F /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
112177752CC283BC000A146F /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
112177782CC283BC000A146F /* LiveActivityBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveActivityBundle.swift; sourceTree = "<group>"; };
1121777A2CC283BC000A146F /* LiveActivityLiveActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveActivityLiveActivity.swift; sourceTree = "<group>"; };
1121777C2CC283BC000A146F /* LiveActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveActivity.swift; sourceTree = "<group>"; };
1121777E2CC283BC000A146F /* AppIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIntent.swift; sourceTree = "<group>"; };
112177802CC283BD000A146F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
112177822CC283BD000A146F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
645C1B152CCBB3BF00251157 /* OnboardingWelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingWelcomeView.swift; sourceTree = "<group>"; };
645C1B172CCBB53C00251157 /* OnboardingNotiPermissionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingNotiPermissionView.swift; sourceTree = "<group>"; };
645C1B192CCBBB4800251157 /* OnboardingPrivacyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingPrivacyView.swift; sourceTree = "<group>"; };
645C1B1B2CCBBE7000251157 /* OnboardingWarningView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingWarningView.swift; sourceTree = "<group>"; };
645C1B1D2CCBBFAB00251157 /* OnboardingStandRecommendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingStandRecommendView.swift; sourceTree = "<group>"; };

1159334B2CDB2A7C005902F2 /* HornSoundClassifier_V11.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = HornSoundClassifier_V11.mlmodel; sourceTree = "<group>"; };

64F73A242CBAC9F100D2A140 /* HornSoundDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = HornSoundDetector.swift; path = hearo/Sources/Presentations/Working/ViewModel/HornSoundDetector.swift; sourceTree = SOURCE_ROOT; };
64F73A262CBAD1C000D2A140 /* SoundDetectorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SoundDetectorViewModel.swift; path = hearo/Sources/Presentations/Working/ViewModel/SoundDetectorViewModel.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -502,7 +493,9 @@
00A04EA32CB7CA510031DECC /* Helper */ = {
isa = PBXGroup;
children = (
00FC15152CDA10B700FBCE0C /* HornSoundClassifier_V9.mlmodel */,

1159334B2CDB2A7C005902F2 /* HornSoundClassifier_V11.mlmodel */,

64F73A242CBAC9F100D2A140 /* HornSoundDetector.swift */,
64F73A262CBAD1C000D2A140 /* SoundDetectorViewModel.swift */,
001D669A2CDB3E11005746AC /* Haptic.swift */,
Expand All @@ -524,8 +517,6 @@
children = (
112177782CC283BC000A146F /* LiveActivityBundle.swift */,
1121777A2CC283BC000A146F /* LiveActivityLiveActivity.swift */,
1121777C2CC283BC000A146F /* LiveActivity.swift */,
1121777E2CC283BC000A146F /* AppIntent.swift */,
112177802CC283BD000A146F /* Assets.xcassets */,
112177822CC283BD000A146F /* Info.plist */,
);
Expand Down Expand Up @@ -796,7 +787,7 @@
00078BEB2CAFC7B000FB3F70 /* HomeView.swift in Sources */,
0045C6BA2CC02969009B4261 /* WarningViewModel.swift in Sources */,
001C6F7E2CAFBC6900B03767 /* hearoApp.swift in Sources */,
645C1B182CCBB53C00251157 /* OnboardingNotiPermissionView.swift in Sources */,

00078BE92CAFC7A800FB3F70 /* OnboardingViewModel.swift in Sources */,
00078BDF2CAFC75900FB3F70 /* FinishView.swift in Sources */,
64F73A272CBAD1C000D2A140 /* SoundDetectorViewModel.swift in Sources */,
Expand All @@ -805,6 +796,7 @@
64F73A252CBAC9F100D2A140 /* HornSoundDetector.swift in Sources */,
645C1B1A2CCBBB4800251157 /* OnboardingPrivacyView.swift in Sources */,
0045C6B82CC0295F009B4261 /* WarningView.swift in Sources */,
1159334C2CDB2A7C005902F2 /* HornSoundClassifier_V11.mlmodel in Sources */,
00078BE72CAFC79E00FB3F70 /* OnboardingView.swift in Sources */,
00078BE52CAFC79400FB3F70 /* SplashView.swift in Sources */,
);
Expand Down Expand Up @@ -856,8 +848,6 @@
buildActionMask = 2147483647;
files = (
112177792CC283BC000A146F /* LiveActivityBundle.swift in Sources */,
1121777F2CC283BC000A146F /* AppIntent.swift in Sources */,
1121777D2CC283BC000A146F /* LiveActivity.swift in Sources */,
1121777B2CC283BC000A146F /* LiveActivityLiveActivity.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1026,7 +1016,9 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"hearo/Preview Content\"";
DEVELOPMENT_TEAM = J5N8Y9F8Z8;

DEVELOPMENT_TEAM = GT56H2MYWV;

ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = hearo/Info.plist;
Expand Down Expand Up @@ -1061,7 +1053,9 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"hearo/Preview Content\"";
DEVELOPMENT_TEAM = J5N8Y9F8Z8;

DEVELOPMENT_TEAM = GT56H2MYWV;

ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = hearo/Info.plist;
Expand Down Expand Up @@ -1171,7 +1165,9 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"HearoadWatch Watch App/Preview Content\"";
DEVELOPMENT_TEAM = J5N8Y9F8Z8;

DEVELOPMENT_TEAM = GT56H2MYWV;

ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "HearoadWatch-Watch-App-Info.plist";
Expand Down Expand Up @@ -1202,7 +1198,9 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"HearoadWatch Watch App/Preview Content\"";
DEVELOPMENT_TEAM = J5N8Y9F8Z8;

DEVELOPMENT_TEAM = GT56H2MYWV;

ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "HearoadWatch-Watch-App-Info.plist";
Expand Down Expand Up @@ -1314,7 +1312,9 @@
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = J5N8Y9F8Z8;

DEVELOPMENT_TEAM = GT56H2MYWV;

GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = LiveActivity/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = LiveActivity;
Expand Down Expand Up @@ -1342,7 +1342,9 @@
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = J5N8Y9F8Z8;

DEVELOPMENT_TEAM = GT56H2MYWV;

GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = LiveActivity/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = LiveActivity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "110455E7-1FA8-4625-B070-43238F2335E4"
type = "1"
version = "2.0">
</Bucket>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Combine
class HornSoundDetector: NSObject, ObservableObject {
private var audioEngine: AVAudioEngine!
private var inputNode: AVAudioInputNode!
private var soundClassifier: HornSoundClassifier_V9?
private var soundClassifier: HornSoundClassifier_V11?
private var streamAnalyzer: SNAudioStreamAnalyzer?
// private var backgroundTask: UIBackgroundTaskIdentifier = .invalid

Expand Down Expand Up @@ -55,7 +55,7 @@ class HornSoundDetector: NSObject, ObservableObject {
do {
let config = MLModelConfiguration()
config.computeUnits = .cpuOnly
soundClassifier = try HornSoundClassifier_V9(configuration: config)
soundClassifier = try HornSoundClassifier_V11(configuration: config)
print("CPU 전용 설정으로 소리 분류기 생성 성공")
} catch {
print("소리 분류기 생성 실패: \(error)")
Expand Down

0 comments on commit 51b235f

Please sign in to comment.