CareKit和ResearchKit冲突

时间:2018-06-09 14:06:58

标签: ios iphone swift researchkit carekit

我对调查结果类型有疑问。 如果我使用CareKit / HealthKit调查,一切都很好,当我想将它与ResearchKit调查混合时 - 我在下面的方法中有错误:

.

这是 - 我认为 - 因为我无法创建一个OCKCarePlanEventResult对象[answer和numericResult都是nil]。

我在下面的扩展中更新症状跟踪器:

func buildCarePlanResultFrom(taskResult: ORKTaskResult) -> OCKCarePlanEventResult {
    guard let firstResult = taskResult.firstResult as? ORKStepResult,
        let stepResult = firstResult.results?.first else {
            fatalError("Unexepected task results")
    }
    if let numericResult = stepResult as? ORKNumericQuestionResult,
        let answer = numericResult.numericAnswer {
        return OCKCarePlanEventResult(valueString: answer.stringValue, unitString: numericResult.unit, userInfo: nil)
    } else {

    }

    fatalError("Unexpected task result type")
}

如何建议如何将ResearchKit的结果类型转换为CareKit或其他解决方案以更新视图?

五月,这将是有用的,任务的例子:

extension TabBarViewController: ORKTaskViewControllerDelegate {
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith
    reason: ORKTaskViewControllerFinishReason, error: Error?) {
    defer {
        dismiss(animated: true, completion: nil)
    }
    guard reason == .completed else { return }
    guard let symptomTrackerViewController = symptomTrackerViewController,
        let event = symptomTrackerViewController.lastSelectedAssessmentEvent else { return }
    symptomTrackerViewController.progressRingTintColor = .lightGreen
    symptomTrackerViewController.delegate = self
    let carePlanResult = carePlanStoreManager.buildCarePlanResultFrom(taskResult: taskViewController.result)
    carePlanStoreManager.store.update(event, with: carePlanResult, state: .completed) {
        success, _, error in
        if !success {
            print(error?.localizedDescription)
        }
    }
}}

1 个答案:

答案 0 :(得分:0)

返回任务的函数sleepHoursSurveyAssessmentTask没有数字答案格式。您使用的ORKTextChoiceAnswerFormat可以使用ORKTaskResultORKChoiceQuestionResult中提取。