Can't create/write files in iOS filesystem
-
Hi!
I have found some posts related to this problem, but I couldn't find a solution yet. This is my situation:QString id = "project_01"; QString dir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]; dir += "/" + id; if (!QDir(dir).exists()) { if (!QDir().mkdir(dir)) { qDebug() << "Fatal error: Insufficient premissions to create directory -> " << dir; return; } }
I got this message from console:
Fatal error: Insufficient permissions to create directory -> "/private/var/mobile/Containers/Data/Application/2887FBCE-B1C0-421B-A880-59F97B9W1F8C/project_01"
Trying to fix the problem, I used these other options with no luck:
QString dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); QString dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); QString dir = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
I am using Qt 5.8 and testing with an iPad Air and an iPad 2. Same result. Any suggestion?
PS: I wonder if it isn't necessary to add some +write permission into the Info.plist file of the app. In Android this is required to create files and directories but I have no experience on iOS.
-
Solved using this path:
QString dir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0];
@xtingray I'm also using this location to create/write files:
QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0)
works on Android and iOS
HomeLocation works on Android but not iOS
-
Your suggestion worked pretty well in Windows and Android. For some reason, it failed in my iPad 2. Anyway thanks! :)
@xtingray just verified:
installed app new on iPad Mini 2, so all my directories will be created new, then data downloaded from REST and stored at AppDataLocation.
all works wellAllTourse HTTP STATUS: 200 Bytes: 92951 Data Bytes written: 92951 to Tours file: "/var/mobile/Containers/Data/Application/E08AB1F2-C3A6-419E-A413-3A4739B0AFE9/Library/Application Support/ProfSYS/data/profsys/tours/allTours.json"
Qt 5.8 QtQuickControls2 App
iOS 10.1
then updated to iOS 10.2.1, deleted app did againall is working as expected