iOS file access permission
-
wrote on 5 Mar 2021, 13:38 last edited by
I'm trying to access files in the downloads folder on iOS for both reading and writing. My application does this successfully on Android, but on iOS permission is not being granted. I added
NSDownloadsFolderUsageDescription
to the info.plist file, which according to the apple developer site should do the trick (https://developer.apple.com/documentation/bundleresources/information_property_list/nsdownloadsfolderusagedescription). But it's still not working for me.On android I had to add some extra code to explicitly trigger the app to request permission. Do I need to do the same on iOS?
-
Hi,
IIRC, you may have to add an entitlement to your app. See here.
-
wrote on 6 Mar 2021, 19:13 last edited by
hmm, I added that to my info.plist and it didn't help.
I'm not sure how the iOS filesystem works. I don't see a downloads folder on my iPad like I have on my android phone and my windows PC. I do see that some of the other apps on my iPad have their own data folders that I can browse using finder. Also, my app never asks me to grant permission to access the downloads folder.
In case it helps, my app uses QStandardPaths to choose the location. On iOS, I have success with opening files using QStandardPaths::AppDataLocation but not with QStandardPaths::DownloadLocation (both of these worked fine on android).
-
iOS security model is not the same as Android and it does not expose the system's ressources in the same manner.
Did you check the entitlements in Xcode ?
-
wrote on 6 Mar 2021, 23:43 last edited by
I don't see any security, sandbox mode, or other file-related things in the capabilities menu, which as far as I can tell is where entitlements are in xcode now for iOS.
-
macOS and iOS are two different beasts. I think you should take a look at this:
https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories -
wrote on 8 Mar 2021, 04:38 last edited by
Before seeing this reply, I figured out that the reason it wasn't working is because the downloads folder at the path that came form QStandardPaths didn't exist. Now my app can read and write those files. However, I can't find it through the iPad browser or when I try to browse on my mac. I think that I can't find it because the the path I'm using now from QStandardPaths is part of the app's sandbox.
Anyway, I'll have to implement a file dialog to try your solution. Would QFileDialog do the trick?
-
QFileDialog uses the system dialog by default on systems that provide one. I am currently unsure that it will fit your use case but I haven't used it directly on iOS for a long time.
-
QFileDialog uses the system dialog by default on systems that provide one. I am currently unsure that it will fit your use case but I haven't used it directly on iOS for a long time.
-
Did you already do Objective-C++ ?
-
@SGaist well FileDialog doesn't seem to do the trick, I'm still restricted to the app's sandbox. I really have no idea how to implement the objective-C controller in QT. Any suggestions?
wrote on 12 Apr 2024, 08:30 last edited by@kgregory Even this topic is old, I've stumbled over it and had similar issues: For me it seems that you'll still stay in the sandbox anyway. The Dialogs might help to get access to outside folders.
This answer is giving a very usefull example on native code: https://stackoverflow.com/questions/46588201/no-files-found-on-ios-devices-qt-creator-c-qstandardpathsstandardlocationsq
With the use of the simulator you can check the filesystem of iOS and have a peek on what is going on. I've found that the native code of the example also does not leave the sandbox. It's about the project settings (namely the Info.plist's UIFileSharingEnable bool (true)) that is exposing your sandbox at least to the iOS file app.