Reputation: 675
On Android I was able to download a pdf file inside the Downloads folder using the package downloads_path_provider
, but on IOS I got an error using this package.
If I use getApplicationDocumentsDirectory()
I get the path: /var/mobile/Containers/Data/Application/EBB52CAB-7783-489A-B9C4-4BB7A093B8C3/Documents
I want to put the download file inside the Files of an iphone
Upvotes: 26
Views: 46333
Reputation: 3193
You should instead use Path Provider for accessing more than just the download directory. It's an official Flutter plugin that's easy to use.
For accessing the document directory using Path Provider
, use the following:
Directory documents = await getApplicationDocumentsDirectory();
This will allow you to store files in the document storage. You might need to add a permission for accessing the document directory within the Files app.
EDIT: Rafael Honda linked to this post that explains how to add that permission.
Directory documents = await getExternalStorageDirectory();
Keep in mind that both of these directories are visible to user.
Upvotes: 30
Reputation: 312
UISupportsDocumentBrowser
to Info.plist and set true
Then you can see the folder with your app name in file app.
But need to use
await getApplicationDocumentsDirectory();
to save the file to be available in file app in iOs.
learn more at
Upvotes: 5
Reputation: 291
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
Added these keys and tried a bunch of things, at the time of this post. The solution for me was of course to add both these two keys and use iOS 14 (14.1 to be exact) rather than iOS 15. this is because iOS 15 did not support downloading and storing in the downloads folder on emulator for some reason.
Upvotes: 8
Reputation: 161
Get the path
For accessing the Document directory you should use a Flutter plugin for finding commonly used locations on the filesystem. The most popular is path_provider
iOS Files app
For download files in your app's folder inside the Files app on the user's device, you should update info.plist.
UISupportsDocumentBrowser (Boolean - iOS) Specifies that the app is a document-based app and uses the UIDocumentBrowserViewController class.
If this key is set to YES, the user can set the document browser’s default save location in Settings. Additionally, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a Document Browser. Users can open and edit these document in place.
This key is supported in iOS 11 and later.
For more information read the docs: https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW37
Upvotes: 12