Apple Health Frameworks

Nov 29 2022 Swift 5, iOS 15, Xcode 13

Part 3: Take Advantage of CareKit & ResearchKit

11. Make an ActiveTask Using ResearchKit.

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 10. Make a Follow-Up Vaccination Task Next episode: 12. Extract OCKOutcomeValue from ORKTaskResult

This video Make an ActiveTask Using ResearchKit. was last updated on Nov 29 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Part 3, Episode 12, Make an ActiveTask using ResearchKit

In this episode, I want to show you how to make an active task to ask a user to do something physically by using the researchkit.

case motionCheck
  static func motionSurvey() -> ORKTask {
    let surveyTask = ORKOrderedTask.shoulderRangeOfMotionTask(
      withIdentifier: IdentifierModel.motionStep.rawValue,
      limbOption: .left,
      intendedUseDescription: nil,
      options: [.excludeConclusion]
    )
    let completionStep = ORKCompletionStep(identifier: IdentifierModel.motionCompletion.rawValue)
    completionStep.title = "All done!"
    completionStep.detailText = "We know the road to recovery can be painful. Keep up the good work!"
    surveyTask.appendSteps([completionStep])
    return surveyTask
  }
  static func makeMotionCheck(date: Date) -> OCKTask {
    let thisMorning = Calendar.current.startOfDay(for: date)
    let nextWeek = Calendar.current.date(
      byAdding: .weekOfYear,
      value: 1,
      to: date
    )
    let nextMonth = Calendar.current.date(
      byAdding: .month,
      value: 1,
      to: thisMorning
    )
    let dailyElement = OCKScheduleElement(
      start: thisMorning,
      end: nextWeek,
      interval: DateComponents(day: 1),
      text: nil,
      targetValues: [],
      duration: .allDay
    )
    let weeklyElement = OCKScheduleElement(
      start: nextWeek ?? Date(),
      end: nextMonth,
      interval: DateComponents(weekOfYear: 1),
      text: nil,
      targetValues: [],
      duration: .allDay
    )
    let schedule = OCKSchedule(
      composing: [dailyElement, weeklyElement]
    )
    let task = OCKTask(
      id: TaskModel.motionCheck.rawValue,
      title: "Range Of Motion",
      carePlanUUID: nil,
      schedule: schedule
    )
    return task
  }
,
                    // Add MotionCheck
                    TaskManager.makeMotionCheck(date: answer)
    case .motionCheck:
      let viewController = OCKSurveyTaskViewController(
        taskID: TaskModel.motionCheck.rawValue,
        eventQuery: OCKEventQuery(for: date),
        storeManager: storeManager,
        survey: SurveyManager.motionSurvey(),
        extractOutcome: { _ in return [OCKOutcomeValue(Date())] })
      viewController.surveyDelegate = delegate
      viewController.view.isUserInteractionEnabled = !isFuture
      viewController.view.alpha = isFuture ? 0.4 : 1.0
      listViewController.appendViewController(viewController, animated: false)
if id == TaskModel.checkIn || id == TaskModel.secondVaccinationCheck || id == TaskModel.motionCheck