Open rtiagom opened 1 month ago
I was able to make it work by creating a Swift plugin that accepts the filename and the contents. With the plugin-fs, before I call writeTextFile, I also call save() from plugin-dialog and get a file URL that I pass to writeTextFile. The issue might be with either plugin-fs or plugin-dialog.
Both plugin-fs and plugin-dialog say that they support iOS.
@objc public func write(_ invoke: Invoke) throws {
logger.log("Write To File function call")
let args = try invoke.parseArgs(WriteFsArgs.self)
let filename = args.filename;
let fileManager = FileManager.default
guard let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
logger.log("Could not locate Documents directory")
invoke.reject("Could not locate Documents directory")
return
}
let fileURL = documentsURL.appendingPathComponent(filename)
do {
try args.content.write(to: fileURL, atomically: true, encoding: .utf8)
logger.log("File written successfully to \(fileURL.path)")
invoke.resolve(["success": 1])
} catch {
logger.log("Failed to write to file: \(error.localizedDescription)")
invoke.resolve(["success": 0])
}
}
After some testing, the problem seems to lie with plugin-dialog. Calling save dialog returns a file path that is unusable with writeTextFile in iOS
writeTextFile does not work with iOS. The code completes without any errors, but the iOS simulator and actual device show an empty file.