CareKit
CareKit copied to clipboard
Multiple Occurrences of One Task in a Day
I'm working on a project in which I'm attempting to schedule one CareKit task (a survey) multiple times daily. To enable this, I'm using the OCKSchedule constructor to create a schedule for my task, and composing two OCKScheduleElements in the process. The relevant portions of my code are as follows:
let thisMorning = Calendar.current.startOfDay(for: Date())
let beforeBreakfast = Calendar.current.date(byAdding: .hour, value: 8, to: thisMorning)!
let afterLunch = Calendar.current.date(byAdding: .hour, value: 12, to: thisMorning)!
let schedule = OCKSchedule(composing: [
OCKScheduleElement(start: beforeBreakfast, end: afterLunch,
interval: DateComponents(day: 1)),
OCKScheduleElement(start: afterLunch, end: nil,
interval: DateComponents(day: 1))
])
var survey = OCKTask(id: "survey", title: "Take a Survey", carePlanUUID: nil, schedule: schedule)
survey.impactsAdherence = true
addTasks([survey], callbackQueue: .main, completion: nil)
However, when I run this code, and complete the survey twice, once in the morning (between 8:00AM and noon), and once in the afternoon, my CareKit completion wheel does not fully close. I suspect it only registers that the survey has been completed once, as the circle does not close further between the first and second completions of the survey.
Is this the right way to schedule the same CareKit task multiple times? Or is there a superior way to be doing so?
Thank you so much in advance!
(Also - I feel a bit bad using Github like a Q&A forum even though... this seems like the place where other people ask such questions about CareKit. Please let me know if this question is better posted elsewhere!)
Thanks for you question Cooper! This is indeed the right place to put your questions, no need to feel bad!
At first blush, it looks like you're doing everything correctly. Let me try this code out locally and see if I experience the same issue. Can you just confirm which branch or commit you have checked out?
Let me ask a couple follow up questions too:
-
Which task view controller are you using to present the survey? Is it the
OCKInstructionsTaskViewController? -
How are you persisting the answers the 2nd time the survey is completed?