Application crashing with UIApplicationEndBackgroundTaskError

George_E picture George_E · Aug 20, 2019 · Viewed 8.4k times · Source

Context: My app is made using SwiftUI, which is a game using SpriteKit.

When pressing the home button on my device, my app encounters an error called 'UIApplicationEndBackgroundTaskError'. The log looks like so:

Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

I have tried making the breakpoint, but it doesn't give me any helpful information I understand. There is no log, it just shows the Debug Navigator.

Debug Navigator

I tried to investigate where the issue came from. I just added some simple print statements. The print Update repeats a few times quickly, before the application is halted by the breakpoint:

struct SceneView: UIViewRepresentable {

    let bounds: CGRect


    // Conformance to UIViewRepresentable
    func makeUIView(context: Context) -> SKView {
        SKView(frame: bounds)
    }
    func updateUIView(_ uiView: SKView, context: Context) {
        print("Update")

        let scene = Scene(size: bounds.size)
        uiView.ignoresSiblingOrder = true
        uiView.showsFPS = true
        uiView.showsDrawCount = true
        uiView.showsNodeCount = true
        uiView.presentScene(scene)
    }
}

  • What is causing the issue, and how can I fix this?
  • Could this be due to SwiftUI or my Xcode betas and iPhone betas not matching up?

Answer

JERC picture JERC · Oct 23, 2019

It is fixed on iOS 13.2 beta 3, you can test it there, it should be fixed.