【问题标题】:Can't use Researchkit with SwiftUI不能将 Researchkit 与 SwiftUI 一起使用
【发布时间】:2021-07-31 21:36:09
【问题描述】:

我正在 SwiftUI 应用程序中使用 researchkit 进行我正在进行的研究。每次我调用研究工具包任务时,应用程序都会崩溃并出现以下错误:

*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[SwiftUI.AppDelegate 窗口]:无法识别的选择器发送到实例 0x600000c511c0” 以 NSException 类型的未捕获异常终止

我目前正在调试一些时间。代码如下:

struct ActivityView: UIViewControllerRepresentable {
var activity: Activity
var onCompleted: (Bool) -> Void

func makeUIViewController(context: Context) -> ORKTaskViewController {
    let result: ORKTaskViewController
    switch activity {
    case .survey:
        result = ORKTaskViewController(task: StudyTasks.surveyTask, taskRun: NSUUID() as UUID)
    
    case .microphone:
        result = ORKTaskViewController(task: StudyTasks.microphoneTask, taskRun: NSUUID() as UUID)
        
        do {
            let defaultFileManager = FileManager.default
            
            // Identify the documents directory.
            let documentsDirectory = try defaultFileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
            
            // Create a directory based on the `taskRunUUID` to store output from the task.
            let outputDirectory = documentsDirectory.appendingPathComponent(result.taskRunUUID.uuidString)
            try defaultFileManager.createDirectory(at: outputDirectory, withIntermediateDirectories: true, attributes: nil)
            
            result.outputDirectory = outputDirectory
        } catch let error as NSError {
            fatalError("The output directory for the task with UUID: \(result.taskRunUUID.uuidString) could not be created. Error: \(error.localizedDescription)")
        }
        
    case .tapping:
        result = ORKTaskViewController(task: StudyTasks.tappingTask, taskRun: NSUUID() as UUID)
    
    case .trailmaking:
        result = ORKTaskViewController(task: StudyTasks.trailmakingTask, taskRun: NSUUID() as UUID)
    }
    result.view.window?.tintColor = UIColor(named: "AccentColor")
    return result
}

func updateUIViewController(_ uiViewController: ORKTaskViewController, context: Context) {
    uiViewController.delegate = context.coordinator
}

func makeCoordinator() -> Coordinator {
    Coordinator(onCompleted: onCompleted)
}

class Coordinator: NSObject, ORKTaskViewControllerDelegate {
    var onCompleted: (Bool) -> Void

    init(onCompleted: @escaping (Bool) -> Void) {
        self.onCompleted = onCompleted
    }

    public func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
        self.onCompleted(reason == .completed)
    }
    
    func taskViewController(_ taskViewController: ORKTaskViewController, viewControllerFor step: ORKStep) -> ORKStepViewController? {
        return nil
    }
}

}

【问题讨论】:

    标签: ios swiftui researchkit


    【解决方案1】:

    我认为 ResearchKit 中存在错误。在 ORKNavigationContainerView.m

    改变

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

    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;}
    

    【讨论】:

      猜你喜欢
      • 2020-08-05
      • 2020-04-17
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多