rickrvo
rickrvo

Reputation: 565

iOS 14 DispatchQueue.main.async not working

I have this code that was working perfectly and when I updated to ios 14 it stopped working.

Debugging the app I noticed that the code inside the closure was not working.

func replaceWindowRootWith(flow: Flow, step: Step, fadeAnimation: Bool = true, addDelay: Bool = false) -> FlowContributors {
    Flows.whenReady(flow1: flow) { [weak self] root in
        root.hero.isEnabled = true
        root.hero.modalAnimationType = fadeAnimation ? .fade : .none
        if let currentRoot = self?.window?.rootViewController {
            let delay = addDelay ? 0.2 : 0
            DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
                print("REPLACING - \(step.self)")
                Hero.shared.cancel(animate: false)
                currentRoot.hero.replaceViewController(with: root)
            }
        } else {
            self?.window?.rootViewController = root
            self?.window?.makeKeyAndVisible()
        }
    }
    return .one(flowContributor: .contribute(withNextPresentable: flow,
                                             withNextStepper: OneStepper(withSingleStep: step)))
}

The code inside the DispatchQueue closure doesn't run. Anyone had the same problem or found a solution to this yet?

Upvotes: 1

Views: 776

Answers (1)

Martin-Gilles Lavoie
Martin-Gilles Lavoie

Reputation: 584

This is what I get when turning one every memory analysis I can when launching our app. With a bit of luck, I can always find this runloop stuck from a code block.

I have a number of code-blocks chained up to get to that display. I removed some animation-related blocks to simplify runtime yet no cigare. Still looking into it but there is definitly something REALLY fishy in iOS 14 code blocks.

This is also reproducible under iOS SIM 14.1 from XC12.1-GM.

NSRunloop stuck in dispatch

Upvotes: 1

Related Questions