URL::downloadToFile blocks indefinitely when iOS device is offline

In my app I’m using URL::downloadToFile() on iOS. The documentations states, that it is using a native OS background network task. Also the class created by the iOS implementation is called BackgroundDownloadTask.
In my naivety I was hoping, that this means, that JUCE and/or the OS handles the download in the background. But if I disconnect my iPad from the WiFi network, my app hangs indefinitely in

downloadTask->connect()

juce_mac_Network.mm:484

It does not block on macOS though.

@fabian : Is this supposed to block. What is wrong here? The documentation, the implementation or my interpretation of it? If my interpretation is wrong, perhaps you can add a hint to the documentation URL::downloadToFile() to avoid repetition of the same fallacy? (like Michael here presumably)

Thanks & Best,
Ben

So sad that after 4 years this problem still persists and your post hasn’t got a single reply from the developers of Juce.

Anyway, still in 2022 if you kill the DownloadTask object in iOS, the App completely freezes, doesn’t even crash…

Have you found a workaround or a good solution?

Can you please provide some example code? I can delete an in-progress URL::DownloadTask without any issues.

You can try the code posted in this other thread: Crash in URLConnectionState::run() while app is shutting down - #10 by ed95

Just add a button that, when clicked, will call task.reset() and the iOS App freezes.
The destructor of the class FallbackDownloadTask remains stuck in a while loop waiting that some sort of session deletes itself… something that ends up in swift code that I don’t understand.

That code is working almost as expected.

Notice that there is an jassert (success); in the finished callback. When you cancel a download this assertion is caught by the debugger, but Xcode isn’t showing you the backtrace for the thread on which finished is called.

You can either remove the assertion or continue past the break in the debugger.