Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Can't create/write files in iOS filesystem
QtWS25 Last Chance

Can't create/write files in iOS filesystem

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    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.


    Qt Developer

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xtingray
      wrote on last edited by
      #2

      Solved using this path:

          QString dir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0];
      
      

      Qt Developer

      ekkescornerE 1 Reply Last reply
      1
      • X xtingray

        Solved using this path:

            QString dir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0];
        
        
        ekkescornerE Offline
        ekkescornerE Offline
        ekkescorner
        Qt Champions 2016
        wrote on last edited by
        #3

        @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

        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
        5.15 --> 6.8 https://t1p.de/ekkeChecklist
        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

        1 Reply Last reply
        1
        • X Offline
          X Offline
          xtingray
          wrote on last edited by
          #4

          Your suggestion worked pretty well in Windows and Android. For some reason, it failed in my iPad 2. Anyway thanks! :)


          Qt Developer

          ekkescornerE 1 Reply Last reply
          0
          • X xtingray

            Your suggestion worked pretty well in Windows and Android. For some reason, it failed in my iPad 2. Anyway thanks! :)

            ekkescornerE Offline
            ekkescornerE Offline
            ekkescorner
            Qt Champions 2016
            wrote on last edited by ekkescorner
            #5

            @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 well

            AllTourse 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 again

            all is working as expected

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.8 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved