ioscordovacordova-ioscordova-plugin-file

How to save dynamic files accessible to the user?


I'm using the cordova-plugin-file to save pdf files to the user's

async saveDocument(base64Response: string, fileName: string) {
    const folderPath = this.file.documentsDirectory;
    await window.resolveLocalFileSystemURL(
      folderPath,
      (directoryEntry) => {
        directoryEntry.getDirectory(
          'appFolder',
          { create: true, exclusive: false },
          (downloadDirectoryEntry) => {
            downloadDirectoryEntry.getFile(fileName, { create: true, exclusive: false }, (fileEntry) => {
              fileEntry.createWriter(
                async (writer) => {
                  writer.onerror = (error) => {
                    console.log('Write failed: ' + error.toString());
                  };
                  const document = await this.base64ToBlobPdfDocument(base64Response);
                  await writer.write(document);
                },
                (error) => {
                  console.error('writer error', error);
                },
              );
            });
          },
          (error) => {
            console.error('error getting download directory! ', error);
          },
        );
      },
      (error) => {
        console.error('error getting data directory! ', error);
      },
    );
  }

In Android it works fine, it is accessible to the user but in iOS I can't find the file.

I tried with the following settings but it didn't work.

config.xml file:

<platform name="ios">
        <edit-config file="*-Info.plist" mode="merge" target="UIFileSharingEnabled">
            <string>Es necesario acceder a los directorios del dispositivo</string>
        </edit-config>
        <edit-config file="*-Info.plist" mode="merge" target="LSSupportsOpeningDocumentsInPlace">
            <string>Es necesario abrir documentos desde la aplicaciĆ³n</string>
        </edit-config>
        <edit-config file="*-Info.plist" mode="merge" target="UISupportsDocumentBrowser">
            <string>Es necesario acceder al buscador de documentos</string>
        </edit-config>
</platform>

Solution

  • Finally it worked with the following configuration

        <config-file platform="ios" target="*-Info.plist" parent="UIFileSharingEnabled">
            <true/>
        </config-file>
        <config-file platform="ios" target="*-Info.plist" parent="LSSupportsOpeningDocumentsInPlace">
            <true/>
        </config-file>
        <config-file platform="ios" target="*-Info.plist" parent="UISupportsDocumentBrowser">
            <true/>
        </config-file>