I'm using an NSURLSession for background downloads, and even though the download is apparently successful, didFinishDownloadingToURL is giving a URL that the app doesn't have permission to access. An example:
/var/mobile/Library/Caches/com.apple.nsurlsessiond/Downloads/com.company.appname/CFNetworkDownload_u0dx1W.tmp
Usually, downloads are successful. In that case, the URL from didFinishDownloadingToURL looks like this:
/private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx/Library/Caches/com.apple.nsurlsessiond/Downloads/com.company.appname/CFNetworkDownload_u0dx1W.tmp
The big problem is that once I start getting bad URLs, nsurlsessiond seems to be stuck in that state. Failures continue even after rebooting the device or deleting and reinstalling the app. I've observed this problem with iOS 10.2 and the iOS 10.3 betas. Has anyone seen something similar and found a workaround? This really looks to me like an iOS bug.
—Chris