Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResearchKit needs update for iOS 13 with addition of SceneDelegate #1464

Open
kwanhlee opened this issue Jul 25, 2021 · 5 comments
Open

ResearchKit needs update for iOS 13 with addition of SceneDelegate #1464

kwanhlee opened this issue Jul 25, 2021 · 5 comments

Comments

@kwanhlee
Copy link

Due to the addition of sceneKit, var window: UIWindow? has moved from AppDelegate to SceneDelegate. A lot of the code depends on the window variable. When var window: UIWindow? is declared inside AppDelegate, it causes UI errors, where navigation bar seems to have a transparent view. The Demo needs to be updated to support latest iOS.

Simulator Screen Shot - iPhone SE (2nd generation) - 2021-07-24 at 18 38 13

@kwanhlee
Copy link
Author

This is the snippet of my code:

  • The viewController is embedded inside a UINavigationController
import UIKit
import ResearchKit

struct SurveyTask {
    static let surveyTask: ORKOrderedTask = {
        var steps = [ORKStep]()
        
        // Instruction step
        let instructionStep = ORKInstructionStep(identifier: "IntroStep")
        instructionStep.title = "Knoweledge of the Universe Survey"
        instructionStep.text = "Please answer these 6 questions to the best of your ability. It's okay to skip a question if you don't know the answer."
        
        steps += [instructionStep]
        
        // Quest question using text choice
        let questQuestionStepTitle = "Which of the following is not a planet?"
        let textChoices = [
            ORKTextChoice(text: "Saturn", value: 0 as NSCoding & NSCopying & NSObjectProtocol),
            ORKTextChoice(text: "Uranus", value: 1 as NSCoding & NSCopying & NSObjectProtocol),
            ORKTextChoice(text: "Pluto", value: 2 as NSCoding & NSCopying & NSObjectProtocol),
            ORKTextChoice(text: "Mars", value: 3 as NSCoding & NSCopying & NSObjectProtocol)
        ]
        let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: textChoices)

        let questQuestionStep = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle, answer: questAnswerFormat)
        questQuestionStep.isOptional = false
        steps += [questQuestionStep]
        
        // Name question using text input
        let nameAnswerFormat = ORKTextAnswerFormat(maximumLength: 25)
        nameAnswerFormat.multipleLines = false
        let nameQuestionStepTitle = "What do you think the next comet that's discovered should be named?"
        let nameQuestionStep = ORKQuestionStep(identifier: "NameQuestionStep", title: nameQuestionStepTitle, answer: nameAnswerFormat)
        
        steps += [nameQuestionStep]
        
        let summaryStep = ORKCompletionStep(identifier: "SummaryStep")
        summaryStep.title = "Thank you."
        summaryStep.text = "We appreciate your time."
        
        steps += [summaryStep]
        
        return ORKOrderedTask(identifier: "SurveyTask", steps: steps)
    }()
}

class ViewController: UIViewController, ORKTaskViewControllerDelegate {
    func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
        
        let taskResult = taskViewController.result

        dismiss(animated: true, completion: nil)
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let taskViewController = ORKTaskViewController(task: SurveyTask.surveyTask, taskRun: nil)
        taskViewController.delegate = self
        present(taskViewController, animated: true)
        
    }
}

@kwanhlee
Copy link
Author

A workaround is to explicitly set the navigationBar color of the taskViewController to match the background color. However, this should be the library's job, which needs to be updated.

        let taskViewController = ORKTaskViewController(task: SurveyTask.surveyTask, taskRun: nil)
        taskViewController.delegate = self
        taskViewController.navigationBar.backgroundColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1.0)
        present(taskViewController, animated: true)

@priyanka16
Copy link

Hi,
I'm trying to push ORKTaskViewController on a button click in a SwiftUI app.
I don't have AppDelegate or SceneDelegate.
The app is crashing with this message in log:
[SwiftUI.AppDelegate window]: unrecognized selector sent to instance 0x600002aa8870

Xcode Version: 13.2.1
ResearchKit Version: 2.0.0

Is there any workaround for this?

Thanks.

@rlimalgc
Copy link

Hey @priyanka16, you can use the workaround that was described on #1465, the problem is the same, the declaration of the var window: UIWindow? on your app delegate.

@priyanka16
Copy link

priyanka16 commented Dec 12, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants