# URL::downloadToFile blocks indefinitely when iOS device is offline

**URL:** <https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861>\
**Category:** MacOSX and iOS\
**Created:** [August 2, 2018, 3:32pm UTC](https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861 "2018-08-02T15:32:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PixelPacker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pixelpacker/32/9869_2.png) [@PixelPacker](https://forum.juce.com/u/PixelPacker)\
**Post date:** [August 2, 2018, 3:32pm UTC](https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861/1 "2018-08-02T15:32:30Z")

</div>

In my app I’m using URL::downloadToFile() on iOS. The documentations states, that it is using a [native OS _background_ network task](https://github.com/WeAreROLI/JUCE/blob/master/modules/juce_core/network/juce_URL.h#L421). Also the class created by the iOS implementation is called [_Background_DownloadTask](https://github.com/WeAreROLI/JUCE/blob/master/modules/juce_core/native/juce_mac_Network.mm#L650).  
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](https://github.com/WeAreROLI/JUCE/blob/master/modules/juce_core/native/juce_mac_Network.mm#L484)

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](https://forum.juce.com/t/url-downloadtofile-issues/27384/2) here presumably)

Thanks & Best,  
Ben

---

<div class="post-metadata">

**Author:** ![ZioGuido](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zioguido/32/6975_2.png) [@ZioGuido](https://forum.juce.com/u/ZioGuido)\
**Post date:** [July 28, 2022, 9:07am UTC](https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861/2 "2022-07-28T09:07:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [August 2, 2022, 9:50am UTC](https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861/3 "2022-08-02T09:50:49Z")

</div>

> [@ZioGuido](#):
>
> Anyway, still in 2022 if you kill the DownloadTask object in iOS, the App completely freezes, doesn’t even crash…

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

---

<div class="post-metadata">

**Author:** ![ZioGuido](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zioguido/32/6975_2.png) [@ZioGuido](https://forum.juce.com/u/ZioGuido)\
**Post date:** [August 2, 2022, 1:40pm UTC](https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861/4 "2022-08-02T13:40:58Z")

</div>

You can try the code posted in this other thread: [Crash in URLConnectionState::run() while app is shutting down - #10 by ed95](https://forum.juce.com/t/crash-in-urlconnectionstate-run-while-app-is-shutting-down/39211/10)

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.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [August 3, 2022, 8:48am UTC](https://forum.juce.com/t/url-downloadtofile-blocks-indefinitely-when-ios-device-is-offline/28861/5 "2022-08-03T08:48:10Z")

</div>

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.
