Сеттер для 'screen' устарел в iOS 13.0 - PullRequest
0 голосов
/ 13 апреля 2020

Я пытался следовать этому руководству для создания многоэкранного приложения:

https://www.youtube.com/watch?v=UYviLiI2rlY&t=774s

К сожалению, в мин. 25:00 - 26:00 я получаю ошибка и мой внешний экран остается черным:

[Assert] Error in UIKit client: -[UIWindow setScreen:] should not be called if the client adopts
UIScene lifecycle. Call -[UIWindow setWindowScene:] instead.

Мой код:

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var textView: UITextView!
    var additionalWindows = [UIWindow]()

    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(forName: UIScreen.didConnectNotification, object: nil, queue: nil) { [weak self] notification in
            guard let self = self else {return}

            guard let newScreen = notification.object as? UIScreen else {return}
            let screenDimensions = newScreen.bounds

            let newWindow = UIWindow(frame: screenDimensions)
            newWindow.screen = newScreen

            guard let vc = self.storyboard?.instantiateViewController(withIdentifier: "PreviewViewController") as? PreviewViewController else {
                fatalError("Unable to find PreviewViewController")
            }

            newWindow.rootViewController = vc
            newWindow.isHidden = false
            self.additionalWindows.append(newWindow)
        }
    }


}

И у меня есть предупреждение об устаревании в newWindow.screen = newScreen: Setter for 'screen' was deprecated in iOS 13.0, но я не могу найти что-нибудь полезное и не слишком сложное в том, как решить эту проблему.

...