我一直在尝试在 iOS 上保存文件。现在我一直在手机上运行 Xcode。
当我运行该应用程序时,它说已成功保存。但是当我使用 FileApp、FileManager、iCloud 和 Apple crappy Files 应用程序等文件管理器应用程序时,我看不到任何文件。
我的问题是,我从网络搜索中听说,为了保存文件,iOS 为应用程序创建了一个沙盒文件夹。
如果我将它保存到 this.file.documentDirectory,用户如何在 Pages 或 Numbers 应用程序中打开它?(你知道 Apple 的 Word 和 Excel 替代了初学者。)
这是代码。
writeToIOS(opts : {
fileName: string,
text: any
}) : Promise < IResponse < any >> {
let response: IResponse < boolean > = {
success: false,
error: '',
data: false
};
const options: IWriteOptions = {
replace: true
};
return new Promise((resolve, reject) => {
const path = this.file.documentsDirectory;
const directory = 'Attendance Log';
this
.file
.checkDir(path, directory)
.then(res => {
this
.file
.writeFile(path + directory, opts.fileName, opts.text, options)
.then(res => {
response = {
...response,
success: true,
error: res,
data: res
};
resolve(response);
})
.catch(error => reject(error));
})
.catch(() => {
this
.file
.createDir(path, directory, true)
.then(directory => {
this
.file
.writeFile(path + directory.name, opts.fileName, opts.text, options)
.then(res => {
response = {
...response,
success: true,
error: res,
data: res
};
resolve(response);
})
.catch(error => reject(error));
})
.catch(error => reject(error));
});
});
}
编辑:
客户/用户应该做的是能够选择文件并在他/她最喜欢的应用程序中打开它。那是一个文件管理器应用程序或一个编写器或电子表格应用程序。