'iOS Files app not opening the right directory from app when it is running in the background
My app has a feature which allows users to download images and once the download is complete, it opens the Files app showing the downloaded items in the document directory. This works fine when the Files app is killed(i.e. Files app is not running in the background). But when it is in the recent apps, once the app tries to open the downloaded location after the download completes, it only opens up the Files app with the screen where it was left off, i.e. it does not open the downloaded location. Is this a common behaviour of the iOS Files app?
And btw I'm using shareddocuments:// instead of file://
Solution 1:[1]
I've found a solution for this issue. I have been trying to open the files app using the URL "file:///var/mobile/Containers/Data/Application/6907BFDD-8C3F-4269-B669-AB69B219CC9F/Documents/" which I got by using FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
By making a small change to this URL, Files app will open the correct directory no matter where the user has left it open.
Solution:
Add "private/" in front of the URL.
This is what the URL will look like after appending "private/"
"file:///private/var/mobile/Containers/Data/Application/6907BFDD-8C3F-4269-B669-AB69B219CC9F/Documents/"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abhiram Krishna |
