представить ORKTaskViewController программно с использованием ResearchKit - PullRequest
0 голосов
/ 21 октября 2019

Я скачал последний выпуск ResearchKit с GitHub и встроил фреймворк в свой проект.

Используя Ray Wenderlich Tutorial по ResearchKit , я создал SurveyЗадача:

import ResearchKit

public var SurveyTask: ORKOrderedTask {

    var steps = [ORKStep]()

    let instructionStep = ORKInstructionStep(identifier: "IntroStep")
    instructionStep.title = "The Questions Three"
    instructionStep.text = "Who would cross the Bridge of Death must answer me these questions three, ere the other side they see."
    steps += [instructionStep]

    let nameAnswerFormat = ORKTextAnswerFormat(maximumLength: 20)
    nameAnswerFormat.multipleLines = false
    let nameQuestionStepTitle = "What is your name?"
    let nameQuestionStep = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle, question: "Hello?", answer: nameAnswerFormat)
    steps += [nameQuestionStep]

    let questQuestionStepTitle = "What is your quest?"
    let textChoices = [
      ORKTextChoice(text: "Create a ResearchKit App", value: 0 as NSNumber),
      ORKTextChoice(text: "Seek the Holy Grail", value: 1 as NSNumber),
      ORKTextChoice(text: "Find a shrubbery", value: 2 as NSNumber)
    ]
    let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: textChoices)
    let questQuestionStep = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle, question: "Hello?", answer: questAnswerFormat)
    steps += [questQuestionStep]

    let summaryStep = ORKCompletionStep(identifier: "SummaryStep")
    summaryStep.title = "Right. Off you go!"
    summaryStep.text = "That was easy!"
    steps += [summaryStep]

    return ORKOrderedTask(identifier: "SurveyTask", steps: steps)
}

делегат в моем ViewController настроен так:

extension ViewController: ORKTaskViewControllerDelegate {

    func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
        taskViewController.dismiss(animated: true, completion: nil)
    }

}

, а затем в этом ViewController я попытался представить ORKTaskViewController:

@objc func showSurvey() {
    let taskViewController = ORKTaskViewController(task: SurveyTask, taskRun: nil)
    taskViewController.delegate = self
    self.present(taskViewController, animated: true, completion: nil)
}

Я продолжаю получать libc++abi.dylib: terminating with uncaught exception of type NSException, и я не совсем уверен, почему. Я не использую раскадровки, но не понимаю, почему я не смог бы использовать ResearchKit без раскадровки. Я пытался найти реализации этого без раскадровки, но самое близкое, что я смог найти, это this , который все еще использует раскадровку. Любая помощь будет оценена.

1 Ответ

0 голосов
/ 25 октября 2019

После добавления точки останова исключения я обнаружил, что она имеет отношение к _appTintColor в библиотеке ResearchKit.

Эта строка кода в ORKNavigationContainerView.m:

_appTintColor = [[UIApplication sharedApplication].delegate window].tintColor;

не сработало, и я предполагаю, что это потому, что в iOS 13 была введена SceneDelegate.swift, где я программно настраиваю контроллер окна и корневого представления (в отличие от того, чтобы делать это в AppDelegate).

Если вы измените его на что-то вроде этого:

if (@available(iOS 13.0, *)) {
    _appTintColor = [self window] .tintColor;
    // not sure if it's this or [[self window].windowScene windows].firstObject .tintColor;
} else {
    _appTintColor = [[UIApplication sharedApplication].delegate window].tintColor;
}

, тогда оно должно работать. Я не знаком с Obj-c, но я пытался получить окно представления, которое создает экземпляр нового контроллера представления, и это, кажется, работает (не стесняйтесь редактировать).

...