-1

I added the ORKOrderedTask.fitnessCheckTaskWithIdentifier Task and it renders find in the UI. But unlike other simpler tasks containing scale/choice/date questions, I was not able to find the exact way to read the sensor data collected via ORKOrderedTask.fitnessCheckTaskWithIdentifier.

I have used the following:

private var walkingTask : ORKTask {

    return ORKOrderedTask.fitnessCheckTaskWithIdentifier("shortWalkTask", intendedUseDescription: "Take a short walk", walkDuration: 10, restDuration: 5, options: nil)

}

upon task completion the task view controller delegate below is hit.

//ORKTaskViewControllerDelegate
    func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?)

is there a way to drill down into the result object contained in task view controller (taskViewController.result) to get the step count? Or will i have to go through health kit or something and then query the required observation? Request help from anyone who has used this task before and can provide some input on how to fetch the pedometer data (step count specifically) for the duration the task was active?

I'm using swift.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110

1 Answers1

1

The step count is not reflected in the result objects per se. Instead, one of the child ORKFileResult objects, generated from the pedometer recorder, will contain the pedometer records queried from CoreMotion, serialized to JSON.

However, exposing the step count on a result object, sounds like a useful extension / improvement, and we should see if it generalizes to other recorders too. Please open an issue on GitHub and we will see what we can do!

jwe
  • 436
  • 2
  • 4
  • Thanks! glad to know there at least is some way to pluck it out in the way it is now... have you done it? Would you mind sharing the exact nested position inside the object, just in case you got he handy. I could save some time in experimenting. – Viral Patel May 04 '15 at 17:15
  • agree, exposing the step count and other sensor derived information in this task result would really make it easy to use. – Viral Patel May 04 '15 at 17:17
  • Try running the task in the `ORKCatalog` Swift example app. In the Results tab, you can navigate down through the results, and see the hierarchy at every step of the way. At the final `ORKFileResult` leg you'll see a path to a file - that's the JSON file containing the data. – jwe May 04 '15 at 18:07
  • i see a child result "fitness.walk" in the result tab for the fitness task. but this task does not have anything as a member variable which could give me the file path or the observation. – Viral Patel May 05 '15 at 08:09
  • Sorry for delay replying - did you run this on a device, or in the simulator? – jwe May 06 '15 at 17:30
  • Yes, unlikely to work on simulator since you won't have any motion samples. – jwe May 07 '15 at 00:16
  • I finally tried running orkcatalog app on device and am now being able to see the path in results tab. the task result has an ORKStepResult with identifier "fitness.walk" inside which there are three "ORKFileResult" with same identifier. The orkcatalog app does not show anything more than this. So i used the following in my app and tried `taskViewController.result.stepResultForStepIdentifier("fitness.walk")?.results?.first as ORKFileResult`. But I'm always getting a nil for the above statement. Whats wrong with this? – Viral Patel May 11 '15 at 08:01
  • exact code I'm trying to get the path is `if let fileResult = taskViewController.result.stepResultForStepIdentifier("fitness.walk")?.results?.first as? ORKFileResult { if let dirPath = fileResult.fileURL?.absoluteURL?.absoluteString { println("@Viral: File Location for activity task is: " + dirPath) } } else { println("@viral: some issue with orkfileresult") }` – Viral Patel May 11 '15 at 08:02
  • I believe this was the behavior on the original version of ResearchKit but should be fixed in current master. If you still have the problem with current master, please file an issue on GitHub. – jwe Jun 02 '15 at 03:55