Comments (6)
You might want to consider using the HealthKit linked tasks in CareKit. The task can be scheduled to occur every day, and will pull data from HealthKit to populate its outcome. The scheduling logic might look something like this:
func createCalorieTask() -> OCKHealthKitTask {
let calorieLinkage = OCKHealthKitLinkage(
quantityIdentifier: .activeEnergyBurned,
quantityType: .cumulative,
unit: .kilocalorie()
)
let startOfDay = Calendar.current.startOfDay(for: Date())
let dailySchedule = OCKScheduleElement(
start: startOfDay,
end: nil,
interval: DateComponents(day: 1),
duration: .allDay,
targetValues: [OCKOutcomeValue(300)]
)
let calorieTask = OCKHealthKitTask(
id: "calories",
title: "Burn Calories",
carePlanUUID: nil,
schedule: OCKSchedule(composing: [dailySchedule]),
healthKitLinkage: calorieLinkage
)
return calorieTask
}
Now in terms of scheduling a notification, you can choose to either schedule or "unschedule" that 8PM notification whenever the outcome for the task changes.
var query = OCKEventQuery(for: anIntervalEncompassingAFewEvents)
query.taskIDs = ["calories"]
for events in store.anyEvents(matching: query) {
// schedule or unschedule notifications based on the
// progress for each event
}
from carekit.
Hi, thank you for your response. However I still have problems with the notification, since OCKEventQuery doesn't have a member taskIDs
from carekit.
I have problem with the schedule of this task you provided, and I'm struggling to understand how should I use to "schedule and unschedule" the notification based on the calories burned during the day
from carekit.
Hi, thank you for your response. However I still have problems with the notification, since OCKEventQuery doesn't have a member taskIDs
Which branch of CareKit are you using? The main branch should have that property.
I have problem with the schedule of this task you provided
What problem are you running into?
I'm struggling to understand how should I use to "schedule and unschedule" the notification based on the calories burned during the day
You can begin by checking the progress for an event. If the progress is not completed, schedule a notification for 8PM. If the progress is completed, remove the 8PM notification.
from carekit.
`func createCalorieTask() -> OCKHealthKitTask {
let calorieLinkage = OCKHealthKitLinkage(
quantityIdentifier: .activeEnergyBurned,
quantityType: .cumulative,
unit: .kilocalorie()
)
let startOfDay = Calendar.current.startOfDay(for: Date())
let dailySchedule = OCKScheduleElement(
start: startOfDay,
end: nil,
interval: DateComponents(day: 1),
duration: .allDay,
targetValues: [OCKOutcomeValue(300)]
)
let calorieTask = OCKHealthKitTask(
id: "calories",
title: "Burn Calories",
carePlanUUID: nil,
schedule: OCKSchedule(composing: [dailySchedule]),
healthKitLinkage: calorieLinkage
)
return calorieTask
}`
this task should be added to the healthkitstore right? And how do I check the progress to schedule the notification? and the OCKEventQuery(for: anIntervalEncompassingAFewEvents) gives me problem, too
Which branch of CareKit are you using? The main branch should have that property.
it must be 2.1 version
from carekit.
this task should be added to the healthkitstore right?
Yep! The OCKHealthKitPassthroughStore
or an OCKStoreCoordinator
.
And how do I check the progress to schedule the notification?
On 2.1, fetch the event for the task and check to see if the outcome value matches the target value for the schedule (which looks to be 300 calories based on the snippet above). To check compare those two, see OCKAnyEvent.outcome
and OCKAnyEvent.scheduleEvent
OCKEventQuery(for: anIntervalEncompassingAFewEvents) gives me problem
That initializer expects a single date, not a date interval. You can use this initializer instead - OCKEventQuery(dateInterval:)
from carekit.
Related Issues (20)
- Warning when uploading App HOT 7
- Occurrence circles HOT 29
- Error when building on latest Xcode and macOS Ventura HOT 1
- Carekit_CareKitStore emitted errors HOT 1
- Compile Errors HOT 1
- How do you save an CareKit OCKOutcomeValue for an array of ResearchKit ORKChoiceQuestionResults HOT 12
- ORKTextChoice + ORKPredicateStepNavigationRule + CareKit + ResearchKit HOT 10
- Bar chart changes every time i close and reopen the application HOT 9
- Problems integrating HealthKit data into an OCKCartesianChartViewController HOT 1
- CareKitStore-CoreData-NSReadOnlyPersistentStoreOption-ErrorMessage HOT 1
- Create monthly charts HOT 3
- Creating PDF with charts and data from more than one View HOT 1
- Sample app for v3? HOT 1
- CareKit live streaming crashes with multithreaded violations HOT 4
- Updated Content HOT 16
- Watch remote synchronization fails with duplicate Outcome.
- CareKit cannot compile with Xcode 15(beta 2) HOT 1
- Adding a detailed description to the nausea card HOT 3
- Issue with OCKSynchronizedStoreManager HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carekit.