Skip to content

백그라운드 활성화 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions DDanDDan/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>CFBundleURLTypes</key>
Expand All @@ -17,6 +15,8 @@
</array>
</dict>
</array>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>KAKAO_KEY</key>
<string>$(KAKAO_KEY)</string>
<key>LSApplicationQueriesSchemes</key>
Expand All @@ -37,6 +37,8 @@
<string>Pretendard-SemiBold.otf</string>
</array>
<key>UIBackgroundModes</key>
<array/>
<array>
<string>fetch</string>
</array>
</dict>
</plist>
21 changes: 12 additions & 9 deletions DDanDDan/Util/HealthKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ class HealthKitManager: ObservableObject {
completion(kcal)
}

}

}

healthStore.execute(query)
Task {
await enableBackgroundMode()
}
}

func enableBackgroundMode() async {
guard let healthStore = healthStore else { return }

// 백그라운드 처리를 위한 코드
healthStore.enableBackgroundDelivery(for: energyBurnedType, frequency: .immediate) { success, error in
if success {
print("✅ 칼로리 데이터 감지 활성화됨")
} else {
print("❌ 백그라운드 전달 설정 실패: \(error?.localizedDescription ?? "알 수 없는 오류")")
}
do {
try await healthStore.enableBackgroundDelivery(for: energyBurnedType, frequency: .hourly)
} catch let error {
print("Failed to enableBackgroundDelivery \(error)")
}
}

Expand Down