0

I am trying to use surveys from ResearchKit. However, I'm getting a selector instance error when I am trying to present the taskViewController. I followed the example on the documentation and don't know why I'm getting an error. My framework is installed from Cocoapods (ResearchKit 2.0.0)

import UIKit
import ResearchKit

class ViewController: UIViewController, ORKTaskViewControllerDelegate {
    func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
        let taskResult = taskViewController.result
            // You could do something with the result here.

            // Then, dismiss the task view controller.
            dismiss(animated: true, completion: nil)
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let myStep = ORKInstructionStep(identifier: "intro")
        myStep.title = "Welcome to ResearchKit"
        let task = ORKOrderedTask(identifier: "task", steps: [myStep])
        
        let taskViewController = ORKTaskViewController(task: task, taskRun: nil)
        taskViewController.delegate = self
        present(taskViewController, animated: true, completion: nil)
        
    }
}

The error is:

libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[testResearchKit.AppDelegate window]: unrecognized selector sent to instance 0x6000031980b0'
terminating with uncaught exception of type NSException
CoreSimulator 757.5 - Device: iPhone SE (2nd generation) (8C24E83B-05CA-434B-84EF-ADAF742E67B0) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone SE (2nd generation)
  • Due to the adoption of scenes and the scene delegate, the app delegate no longer has a `window` property by default. You can add a property `window` of type `UIWindow?` to your app delegate if you aren't using scenes and multiple views – Paulw11 Jul 25 '21 at 01:52
  • @Paulw11 When I add the UIWindow, the navigationBar of the modally presented controller seems to be transparent. – infiniteObj Jul 25 '21 at 02:01

0 Answers0