You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
VyacheslavBakinskiy
5 years agoHelpful | Level 6
Downloading in the background in iOS (Swift)
Hello, I'm using file download from Dropbox in my app. It works fine when app is active, but if my app goes into the background the download stops. How can I solve it? I use this code to download: ...
- 5 years ago
Hello, Greg!
I have new information regarding my question. On what do you run the code on a real device or on the Xcode simulator? I've always tested on a real device and was getting this issue. I decided to test it on the simulator and was very surprised that the download works fine on it. I also noticed that when I run the code on a real device - I get this issue, but if I then click to download another file, then I'll see that the first file is immediately downloaded, as if it had already been downloaded, but the completion handler didn't work.
What could be the issue? Why does it work fine on the simulator?
P.S. This issue happens only in case when device connected to the PC (Xcode), when I run app without connection to the PC the download works fine.
VyacheslavBakinskiy
Helpful | Level 6
I use 6.0.3 version of SwiftyDropbox. No, I don't get any error. When I return to the app I see that download isn't complete. If you look at my code you'll see that I have completion handler which works when dowload is complete, and after return to the app I see that it didn't work.
Also in the downloadFile func I get download progress (I didn't include it in the question so as not to complicate)
.progress { progressData in
let progress = Double(progressData.fractionCompleted)
completion(progress)
print(progress)
}
When I start downloading a file and then minimize the application, then I'll see that progress stops and it doesn't start again if I return to the app
Greg-DB
5 years agoDropbox Staff
Thanks for the additional information. I just tried reproducing this with the code you provided. While I also see the progress reporting stop when the app is sent to the background, if I then bring it back to the foreground the download does then resume and complete.
Can you let me know how long you're leaving the app in the background before resuming it? Also, what version(s) of iOS are you seeing this with?
- VyacheslavBakinskiy5 years agoHelpful | Level 6
I leave the application in the background for a few seconds. I also tried leaving it on for a few minutes. The result is the same. I'm using iOS 14.
- Greg-DB5 years agoDropbox Staff
Thanks! That's the same as my test setup though, so I'm still not sure why you're seeing a different behavior.
I see you included a line for defining your client object ("private let client..."), but where exactly are you running that? The issue may be related to the lifecycle of that object. If it's no longer available, the operation may not complete. If you try using DropboxClientsManager.authorizedClient directly, does that change the behavior?
Likewise, is it possible your app is just getting terminated entirely when its in the background? You may want to add some logging to see what's happening in the lifecycle of the app.
- VyacheslavBakinskiy5 years agoHelpful | Level 6
I tried to use DropboxClientsManager.authorizedClient?.files.download(...) dicectly but it doesn't solve issue. I sure that my app doesn't getting terminated entirely because I also downloading from Google Drive in the similar conditions and it works fine.
The downloadFile function is a function of the Protocol under which classes for working with Dropbox and Google Drive are signed, and if the problem was in these classes or functions, then I'd have the same problem with downloading from Google Drive.
Suggest me some other solutions, pls, I'm desperate.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 12 months agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!