Potential bug? UnityWebRequest error when resuming app on iOS

Hi,

So am using a UnityWebRequest to download a file from a server. It’s quite big so we expect the user to be able to lock the app and the file continues to download in the background.

Now if the user locks their phone stays on the iOS splashscreen and then resumes, this behaves as expected. If however, the user changes to another app and then comes back to ours, we get an error “Cannot connect to destination host” even though that request has just been connected.

Any thoughts on what this might be? I wondered if this is something to do with how the iOS apps suspends? Should add, behaviour is as expected on Android and PC/Mac.

Thanks,

I haven’d done this personally but I suspect you might need to assert a background processing mode in your Apple entitlements, which is what goes into your provisioning profile.

Here’s some apple docs:

Not sure if any of that will behave well with Unity’s web requests… perhaps someone here who has tinkered with it could add more info.

Oh! I found a tutorial: this guy (Ray Wenderlich) has a TON of great tutorials, so generally it is worth taking a look at his stuff:

If an app goes into background for longer than certain number of seconds, the download are cancelled. This happens in Apple API, so this is by design.
If you want to download a large file and want it to run in background as well, try this: GitHub - Unity-Technologies/BackgroundDownload: Plugins for mobile platforms to enable file downloads in background

Whoa, that seems like an extremely useful thing to keep on hand. Thanks!

Yes I used that in the end. There is a bug with that package though (which I’ve posted about on that githib project).

1 Like