gpt4 book ai didi

ios - 使用 ResearchKit 以编程方式呈现 ORKTaskViewController

转载 作者:行者123 更新时间:2023-11-29 05:23:01 25 4
gpt4 key购买 nike

我下载了 latest release of ResearchKit来自 GitHub 并将该框架嵌入到我的项目中。

使用Ray Wenderlich Tutorial on ResearchKit ,我创建了一个调查任务:

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 中的委托(delegate)设置如下:

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: termination with uncaught exception of type NSException,但我不太清楚为什么。我没有使用 Storyboard,但我不明白为什么没有 Storyboard我就无法使用 ResearchKit。我试图搜索无 Storyboard的实现,但我能找到的最接近的是 this仍然使用 Storyboard。任何帮助将不胜感激。

最佳答案

添加异常断点后发现和_appTintColor有关系在 ResearchKit 库中。

ORKNavigationContainerView.m中的这行代码:

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

不起作用,我假设这是因为 SceneDelegate.swift是在 iOS 13 中引入的,我在其中以编程方式设置窗口和 Root View Controller (而不是在 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,但我试图获取实例化新 View Controller 的 View 窗口,它似乎可以工作(随意编辑)。

关于ios - 使用 ResearchKit 以编程方式呈现 ORKTaskViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58479691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com