plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

[bug] Using plugin-dialog and plugin-fs to write file on iOS is ineffective.

Open nashaofu opened this issue 1 year ago • 5 comments

Replicate the code:https://github.com/shell360/tauri-issue The replication steps:

  1. git clone https://github.com/shell360/tauri-issue.git
  2. cd tauri-issue && pnpm install
  3. run pnpm tauri ios dev,And select the iOS simulator.
  4. click save file button
  5. When checking the file in iOS file management, it was found that the content was not successfully written.
import { useCallback, useState } from 'react'
import { save, open } from '@tauri-apps/plugin-dialog'
import { writeFile, readFile } from '@tauri-apps/plugin-fs'

function App() {
  const onSave = useCallback(async () => {
    const path = await save()
    if (!path) {
      return
    }

    let encoder = new TextEncoder()
    let data = encoder.encode('Hello World')
    await writeFile(path, data) // The content was not successfully written.
  }, [])

  const onOpen = useCallback(async () => {
    const path = await open()
    if (!path) {
      return
    }

    let content = await readFile(path)
    console.log(content)
  }, [])
  
  return (
    <main className="container">
      <button onClick={onSave}>save file</button>
      <button onClick={onOpen}>open file</button>
    </main>
  )
}

export default App

nashaofu avatar Nov 23 '24 14:11 nashaofu

Does everyone help look at this problem?

nashaofu avatar Dec 15 '24 10:12 nashaofu

Here is the bug reproduction in case anyone is interested in addressing this: https://github.com/wxiaoyun/tauri-ios-fs-bug-reproduction

wxiaoyun avatar Feb 01 '25 00:02 wxiaoyun

Have you solved this problem? @wxiaoyun

nashaofu avatar Feb 14 '25 12:02 nashaofu

Have you solved this problem? @wxiaoyun

I did not, currently I am not using the dialog plugin to save files. Just using plugin-fs directly.

Apologies for the lack of experience in native dev. When I try to save files directly to Downloads folder on iOS with plugin-fs, it seems the operation is rejected by the os even with the tauri capabilities configured with the corresponding write permissions. I am not sure if it has something to do with app sandboxing. Currently, I am working around this by downloading the files into the Documents folder of the application and expose the application Documents folder

wxiaoyun avatar Feb 15 '25 03:02 wxiaoyun

Might be related to https://github.com/tauri-apps/tauri/issues/9190. I can only get write speeds of around 2.6 MB/s in debug mode, and 7.6 MB/s in release mode on a very recent M1 MacBook Pro.

chrox avatar Apr 15 '25 14:04 chrox