如何保存用户可访问的动态文件?
How to save dynamic files accessible to the user?
我正在使用 cordova-plugin-file 将 pdf 文件保存到用户的
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);
},
);
}
在 Android 中它工作正常,用户可以访问它但是在 iOS 中我找不到文件。
我尝试了以下设置,但没有用。
config.xml 文件:
<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>
最终它使用以下配置工作
<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>
我正在使用 cordova-plugin-file 将 pdf 文件保存到用户的
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);
},
);
}
在 Android 中它工作正常,用户可以访问它但是在 iOS 中我找不到文件。
我尝试了以下设置,但没有用。
config.xml 文件:
<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>
最终它使用以下配置工作
<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>