1

使用に問題があります

if let wd = UIApplication.shared.delegate?.window {
            var vc = wd!.rootViewController

このコードをディスパッチに入れると、警告メッセージは消えますが、アプリケーションは正しく表示されません。ディスパッチを削除すると、警告メッセージが表示されます。

UIWindow.rootViewController はメインスレッドからのみ使用する必要があります

UIApplication.delegate はメイン スレッドからのみ使用する必要があります

そのクラスは特に、progressBar を使用してダウンロードするためのものです。

      public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
            print("Download finished: \(location)")
...
 do { 
            let result =  try FileManager.default.replaceItemAt(URL(fileURLWithPath: Constants.Path.temp.stringByAppendingPathComponent(path: "temp.zip")), withItemAt: URL(fileURLWithPath: location.path))

            let source = Constants.Path.tempZipFile
            let destination = Constants.Path.temp.stringByAppendingPathComponent(path: "dezipped")
            var myDict = [String:Any]()
            myDict["source"] = source
            myDict["destination"] = destination


            DispatchQueue.main.async { //IF I REMOVE THIS => PB OR THREAD IN MAIN
            if let wd = UIApplication.shared.delegate?.window {
                var vc = wd!.rootViewController
                if(vc is UINavigationController){
                    vc = (vc as! UINavigationController).visibleViewController

                }

                if(vc is WebViewController){
                    NotificationCenter.default.post(name: .DeflatSynchroFilesWebView, object: myDict, userInfo: nil)
                }
                else
                {
                    NotificationCenter.default.post(name: .DeflatSynchroFiles, object: myDict, userInfo: nil)
                }
            }
            }
        } catch let writeError as NSError {
            print("error writing file temp.zip to temp folder")
        }

ここに画像の説明を入力 アプリをバグることなく警告を削除するには?

前もって感謝します。

4

1 に答える 1

0

これが役立つかどうかはわかりませんが、取得するrootViewControllerには常にこれを使用します:

if let window = UIApplication.shared.keyWindow?.rootViewController {

        }

代理人なしで

于 2019-09-05T16:32:28.663 に答える