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

About this episode
Leave a rating/review
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

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

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

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!"
    return surveyTask
  static func makeMotionCheck(date: Date) -> OCKTask {
    let thisMorning = Calendar.current.startOfDay(for: date)
    let nextWeek =
      byAdding: .weekOfYear,
      value: 1,
      to: date
    let nextMonth =
      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